Skip to content

Commit

Permalink
fix: handle uppercase encoding (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <[email protected]>
  • Loading branch information
aurelienbottazini and pi0 authored Aug 17, 2021
1 parent 9dbf95c commit 7a663e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 15 additions & 11 deletions src/encoding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ const EQUAL_RE = /=/g // %3D
const IM_RE = /\?/g // %3F
const PLUS_RE = /\+/g // %2B

const ENC_BRACKET_OPEN_RE = /%5B/g // [
const ENC_BRACKET_CLOSE_RE = /%5D/g // ]
const ENC_CARET_RE = /%5E/g // ^
const ENC_BACKTICK_RE = /%60/g // `
const ENC_CURLY_OPEN_RE = /%7B/g // {
const ENC_PIPE_RE = /%7C/g // |
const ENC_CURLY_CLOSE_RE = /%7D/g // }
const ENC_SPACE_RE = /%20/g
const ENC_SLASH_RE = /%2F/g
const ENC_ENC_SLASH_RE = /%252F/g
const ENC_BRACKET_OPEN_RE = /%5B/gi // [
const ENC_BRACKET_CLOSE_RE = /%5D/gi // ]
const ENC_CARET_RE = /%5E/gi // ^
const ENC_BACKTICK_RE = /%60/gi // `
const ENC_CURLY_OPEN_RE = /%7B/gi // {
const ENC_PIPE_RE = /%7C/gi // |
const ENC_CURLY_CLOSE_RE = /%7D/gi // }
const ENC_SPACE_RE = /%20/gi
const ENC_SLASH_RE = /%2F/gi
const ENC_ENC_SLASH_RE = /%252F/gi

/**
* Encode characters that need to be encoded on the path, search and hash
Expand Down Expand Up @@ -87,7 +87,11 @@ export function encodeQueryKey (text: string | number): string {
* @returns encoded string
*/
export function encodePath (text: string | number): string {
return encode(text).replace(HASH_RE, '%23').replace(IM_RE, '%3F').replace(ENC_ENC_SLASH_RE, '%2F')
return encode(text)
.replace(HASH_RE, '%23')
.replace(IM_RE, '%3F')
.replace(ENC_ENC_SLASH_RE, '%2F')
.replace(AMPERSAND_RE, '%26')
}

/**
Expand Down
3 changes: 2 additions & 1 deletion test/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('normalizeURL', () => {
'http://localhost/?redirect=http://google.com?q=test': 'http://localhost/?redirect=http://google.com?q=test',
'http://localhost/[email protected]': 'http://localhost/[email protected]',
'http://localhost/?email=some%2Bv1%40email.com': 'http://localhost/?email=some%[email protected]',
'http://localhost/abc/deg%2F%[email protected]': 'http://localhost/abc/deg%2F%[email protected]'
'http://localhost/abc/deg%2F%[email protected]': 'http://localhost/abc/deg%2F%[email protected]',
'http://localhost/abc/deg%2f%3f%[email protected]&foo=bar': 'http://localhost/abc/deg%2F%3F%[email protected]&foo=bar'
}

const validURLS = [
Expand Down

0 comments on commit 7a663e2

Please sign in to comment.