Skip to content

Commit

Permalink
fix: do not escape +, -, /
Browse files Browse the repository at this point in the history
  • Loading branch information
double-beep authored Aug 27, 2024
1 parent 3c8c6c7 commit d6bbc81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const helpers = {
getRegexForPathShortener: (path: string, domain?: string): string => {
// https://stackoverflow.com/a/3561711
// https://chat.stackexchange.com/transcript/message/65665204
const escaped = path.replace(/[/\-\\^$*+?.()|[\]{}]/g, '\\$&');
const escaped = path.replace(/[\\^$*?.()|[\]{}]/g, '\\$&');
const mainPart = `(?-i:${escaped})`;
const comment = `(?#${domain || ''})`;

Expand Down
10 changes: 7 additions & 3 deletions test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,13 @@ describe('index helpers', () => {
'3vcWir3': ['bit.ly', '(?-i:3vcWir3)(?#bit.ly)'],
'FNEuyd': ['goo.gl', '(?-i:FNEuyd)(?#goo.gl)'],
'KdxEAt91D7k': ['youtu.be', '(?-i:KdxEAt91D7k)(?#youtu.be)'],
'+jJyLwSpqLeAzNmFi': ['t.me', String.raw`(?-i:\+jJyLwSpqLeAzNmFi)(?#t.me)`],
'davitacols/dataDisk': ['github repository', String.raw`(?-i:davitacols\/dataDisk)(?#github repository)`],
'arjun.muralidharan2': ['facebook', String.raw`(?-i:arjun\.muralidharan2)(?#facebook)`]
// don't escape +
'+jJyLwSpqLeAzNmFi': ['t.me', String.raw`(?-i:+jJyLwSpqLeAzNmFi)(?#t.me)`],
// don't escape /
'davitacols/dataDisk': ['github repository', String.raw`(?-i:davitacols/dataDisk)(?#github repository)`],
'arjun.muralidharan2': ['facebook', String.raw`(?-i:arjun\.muralidharan2)(?#facebook)`],
// don't escape -
'example-test': ['bit.ly', String.raw`(?-i:example-test)(?#bit.ly)`],
}
).forEach(([path, info]) => {
const [domain, expectedValue] = info;
Expand Down

0 comments on commit d6bbc81

Please sign in to comment.