Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/generate-char-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { srcFileContents, specFileContents } = generateCharUtils([
['isQuoteChar', /['"]/],
['isWhitespaceChar', /\s/],
['isAlphaNumericOrMarkChar', alphaNumericAndMarksRe /*/[\p{Letter}\p{Mark}\p{Emoji}\p{Nd}]/u*/], // sadly the unicode regexp is not working, probably because the char codes are outside the range of 0-65535 for multi-char emojis and such, but not 100% sure. Need to investigate. Using the old regexp for now instead
['isValidEmailLocalPartSpecialChar', /[!#$%&'*+/=?^_`{|}~-]/], // special characters that are valid in an email address
['isValidEmailLocalPartSpecialChar', /[!#$%&'*+/=?^_`{|}~;-]/], // special characters that are valid in an email address
['isUrlSuffixAllowedSpecialChar', /[-+&@#/%=~_()|'$*[\]{}\u2713]/], // The set of characters that are allowed in the URL suffix (i.e. the path, query, and hash part of the URL) which may also form the ending character of the URL. The isUrlSuffixNotAllowedAsFinalChar() function allows for additional allowed URL suffix characters, but (generally) should not be the *last* character of a URL.
['isUrlSuffixNotAllowedAsFinalChar', /[?!:,.;^]/], // URL suffix characters (i.e. path, query, and has part of the URL) that are not allowed as the *last character* in the URL suffix as they would normally form the end of a sentence. The isUrlSuffixAllowedSpecialChar() function contains additional allowed URL suffix characters which are allowed as the last character.
['isOpenBraceChar', /[({[]/],
Expand Down
4 changes: 2 additions & 2 deletions src/char-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function isAlphaNumericOrMarkChar(c: number): boolean {
}

/**
* Determines if the given character `c` matches the regular expression /[!#$%&'*+/=?^_`{|}~-]/
* Determines if the given character `c` matches the regular expression /[!#$%&'*+/=?^_`{|}~;-]/
* by checking it via character code in a binary search fashion.
*
* This technique speeds this function up by a factor of ~10x vs. running RegExp.prototype.test()
Expand All @@ -104,7 +104,7 @@ export function isAlphaNumericOrMarkChar(c: number): boolean {
* npm run generate-char-utils
*/
export function isValidEmailLocalPartSpecialChar(c: number): boolean {
return (c < 47 ? (c < 42 ? (c == 33 || (c >= 35 && c <= 39)) : ((c >= 42 && c <= 43) || c == 45)) : (c < 63 ? (c == 47 || c == 61) : (c < 94 ? c == 63 : ((c >= 94 && c <= 96) || (c >= 123 && c <= 126)))));
return (c < 59 ? (c < 42 ? (c == 33 || (c >= 35 && c <= 39)) : (c < 45 ? (c >= 42 && c <= 43) : (c == 45 || c == 47))) : (c < 63 ? (c == 59 || c == 61) : (c < 94 ? c == 63 : ((c >= 94 && c <= 96) || (c >= 123 && c <= 126)))));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/char-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ describe('isAlphaNumericOrMarkChar()', () => {
});

describe('isValidEmailLocalPartSpecialChar()', () => {
it(`should appropriately return true/false to match the regular expression /[!#$%&'*+/=?^_\`{|}~-]/`, () => {
it(`should appropriately return true/false to match the regular expression /[!#$%&'*+/=?^_\`{|}~;-]/`, () => {
for (let charCode = 0; charCode < 65535; charCode++) {
const char = String.fromCharCode(charCode);
const fnResult = isValidEmailLocalPartSpecialChar(charCode);
const regExpResult = /[!#$%&'*+/=?^_`{|}~-]/.test(char);
const regExpResult = /[!#$%&'*+/=?^_`{|}~;-]/.test(char);

expect(fnResult).to.equal(regExpResult, `Expected charCode ${charCode} (${char}) to return ${regExpResult}, but returned ${fnResult}`);
}
Expand Down