<commit_before>import { History } from './base'
import { merge, cached, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, cleanPath } from '../util'

function replaceHash (path) {
  const i = location.href.indexOf('#')
  location.replace(
    location.href.slice(0, i >= 0 ? i : 0) + '#' + path
  )
}

const replaceSlug = cached(path => {
  return path.replace('#', '?id=')
})

export class HashHistory extends History {
  constructor (config) {
    super(config)
    this.mode = 'hash'
  }

  getBasePath () {
    const path = window.location.pathname || ''
    const base = this.config.basePath

    return /^(\/|https?:)/g.test(base)
      ? base
      : cleanPath(path + '/' + base)
  }

  getCurrentPath () {
    // We can't use location.hash here because it's not
    // consistent across browsers - Firefox will pre-decode it!
    const href = location.href
    const index = href.indexOf('#')
    return index === -1 ? '' : href.slice(index + 1)
  }

  onchange (cb = noop) {
    on('hashchange', cb)
  }

  normalize () {
    let path = this.getCurrentPath()

    path = replaceSlug(path)

    if (path.charAt(0) === '/') return replaceHash(path)
    replaceHash('/' + path)
  }

  /**
   * Parse the url
   * @param {string} [path=location.herf]
   * @return {object} { path, query }
   */
  parse (path = location.href) {
    let query = ''

    const queryIndex = path.indexOf('?')
    if (queryIndex >= 0) {
      query = path.slice(queryIndex + 1)
      path = path.slice(0, queryIndex)
    }

    const hashIndex = path.indexOf('#')
    if (hashIndex) {
      path = path.slice(hashIndex + 1)
    }

    return {
      path,<commit_msg>fix(hash): hash routing crashes when url has querystring<commit_after>import { History } from './base'
import { merge, cached, noop } from '../../util/core'
import { on } from '../../util/dom'
import { parseQuery, stringifyQuery, cleanPath } from '../util'

function replaceHash (path) {
  const i = location.href.indexOf('#')
  location.replace(
    location.href.slice(0, i >= 0 ? i : 0) + '#' + path
  )
}

const replaceSlug = cached(path => {
  return path.replace('#', '?id=')
})

export class HashHistory extends History {
  constructor (config) {
    super(config)
    this.mode = 'hash'
  }

  getBasePath () {
    const path = window.location.pathname || ''
    const base = this.config.basePath

    return /^(\/|https?:)/g.test(base)
      ? base
      : cleanPath(path + '/' + base)
  }

  getCurrentPath () {
    // We can't use location.hash here because it's not
    // consistent across browsers - Firefox will pre-decode it!
    const href = location.href
    const index = href.indexOf('#')
    return index === -1 ? '' : href.slice(index + 1)
  }

  onchange (cb = noop) {
    on('hashchange', cb)
  }

  normalize () {
    let path = this.getCurrentPath()

    path = replaceSlug(path)

    if (path.charAt(0) === '/') return replaceHash(path)
    replaceHash('/' + path)
  }

  /**
   * Parse the url
   * @param {string} [path=location.herf]
   * @return {object} { path, query }
   */
  parse (path = location.href) {
    let query = ''

    const hashIndex = path.indexOf('#')
    if (hashIndex) {
      path = path.slice(hashIndex + 1)
    }

    const queryIndex = path.indexOf('?')
    if (queryIndex >= 0) {
      query = path.slice(queryIndex + 1)
      path = path.slice(0, queryIndex)
    }

    return {
      path,
{'fraction_non_alphanumeric': 0.16372066067806432, 'fraction_numerical': 0.005795421616922631, 'mean_word_length': 2.5883575883575882, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '904648', 'n_tokens_mistral': 1161, 'n_tokens_neox': 1121, 'n_words': 290}