From b427ccfedea881bd5582f6e095d2d9f407691e74 Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Sun, 2 Jun 2019 22:55:52 -0400 Subject: [PATCH] fix unicode regex Add /g option like before. Remove manual export. Actually use it in the isNameValid function. --- dist/bundle.es.js | 9 ++++----- src/index.js | 1 - src/lbryURI.js | 7 +++---- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dist/bundle.es.js b/dist/bundle.es.js index 2977116..fb5eae1 100644 --- a/dist/bundle.es.js +++ b/dist/bundle.es.js @@ -822,7 +822,8 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < argument const channelNameMinLength = 1; const claimIdMaxLength = 40; -const regexInvalidURI = /[^A-Za-z0-9-]/g; +// see https://spec.lbry.com/#urls +const regexInvalidURI = exports.regexInvalidURI = /[=&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu; const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/; /** @@ -990,9 +991,8 @@ function isURIValid(URI) { return parts && parts.claimName; } -function isNameValid(claimName, checkCase = true) { - const regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i'); - return regexp.test(claimName); +function isNameValid(claimName) { + return !regexInvalidURI.test(claimName); } function isURIClaimable(URI) { @@ -3766,7 +3766,6 @@ exports.notificationsReducer = notificationsReducer; exports.parseQueryParams = parseQueryParams; exports.parseURI = parseURI; exports.regexAddress = regexAddress; -exports.regexInvalidURI = regexInvalidURI; exports.savePosition = savePosition; exports.searchReducer = searchReducer; exports.selectAbandoningIds = selectAbandoningIds; diff --git a/src/index.js b/src/index.js index 848d0e5..a85a007 100644 --- a/src/index.js +++ b/src/index.js @@ -23,7 +23,6 @@ export { // common export { Lbry }; export { - regexInvalidURI, regexAddress, parseURI, buildURI, diff --git a/src/lbryURI.js b/src/lbryURI.js index 3415b26..8292606 100644 --- a/src/lbryURI.js +++ b/src/lbryURI.js @@ -2,7 +2,7 @@ const channelNameMinLength = 1; const claimIdMaxLength = 40; // see https://spec.lbry.com/#urls -const regexInvalidURI = (exports.regexInvalidURI = /[=&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/u); +const regexInvalidURI = (exports.regexInvalidURI = /[=&#:$@%?\u{0000}-\u{0008}\u{000b}-\u{000c}\u{000e}-\u{001F}\u{D800}-\u{DFFF}\u{FFFE}-\u{FFFF}]/gu); export const regexAddress = /^(b|r)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/; /** @@ -201,9 +201,8 @@ export function isURIValid(URI) { return parts && parts.claimName; } -export function isNameValid(claimName, checkCase = true) { - const regexp = new RegExp('^[a-z0-9-]+$', checkCase ? '' : 'i'); - return regexp.test(claimName); +export function isNameValid(claimName) { + return !regexInvalidURI.test(claimName); } export function isURIClaimable(URI) {