<commit_before>import Listener from './listener'
import warning from 'warning'

function getPathname() {
  return location.pathname
}

function getState() {
  return history.state
}

function invokeHandlers(handlers) {
  function invoke(event, fn) {
    let pathname = getPathname(), state = event.state
    return fn({ pathname, state, event })
  }
  return event => handlers().forEach(invoke.bind(null, event))
}

function createPopstate() {
  return new Listener('popstate', window, invokeHandlers)
}

let push = (cb, msg) => {
  let { pathname, state, title } = msg
  if (pathname !== getPathname()) {
    history.pushState(state, title, pathname)
    console.log('push:', pathname, state)
    if (cb) return cb(msg)
  } else warning(false, 'Attempt to push path identical to current path: %s', pathname)
}

let replace = (cb, msg) => {
  let { pathname, state, title } = msg
  if (!(pathname === getPathname() && state === getState())) {
    history.replaceState(state, title, pathname)
    console.log('replace:', pathname, state)
    if (cb) return cb(msg)
  } else warning(false, 'Attempt to push path identical to current path: %s', pathname)
}

let go = val => val && history.go(val)

export { createPopstate, push, replace, go }<commit_msg>add warning to detect unencoded path in push/replace<commit_after>import Listener from './listener'
import warning from 'warning'

function isEncoded(path) {
  return encodeURI(decodeURI(path)) === path
}

function getPathname() {
  return location.pathname
}

function getState() {
  return history.state
}

function invokeHandlers(handlers) {
  function invoke(event, fn) {
    let pathname = getPathname(), state = event.state
    return fn({ pathname, state, event })
  }
  return event => handlers().forEach(invoke.bind(null, event))
}

function createPopstate() {
  return new Listener('popstate', window, invokeHandlers)
}

let push = (cb, msg) => {
  let { pathname, state, title } = msg
  if (pathname !== getPathname()) {
    warning(isEncoded(pathname), 'Incorrect encoding. Use encodeURI on path: %s', pathname)
    history.pushState(state, title, pathname)
    console.log('push:', pathname, state)
    if (cb) return cb(msg)
  } else warning(false, 'Attempt to push path identical to current path: %s', pathname)
}

let replace = (cb, msg) => {
  let { pathname, state, title } = msg
  if (!(pathname === getPathname() && state === getState())) {
    warning(isEncoded(pathname), 'Incorrect encoding. Use encodeURI on path: %s', pathname)
    history.replaceState(state, title, pathname)
    console.log('replace:', pathname, state)
    if (cb) return cb(msg)
  } else warning(false, 'Attempt to push path identical to current path: %s', pathname)
}

let go = val => val && history.go(val)

export { createPopstate, push, replace, go }
{'fraction_non_alphanumeric': 0.1392857142857143, 'fraction_numerical': 0.0, 'mean_word_length': 4.345419847328245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3461101', 'n_tokens_mistral': 876, 'n_tokens_neox': 869, 'n_words': 274}