From 92fef64467e84b0ad161d8a1f4af0329eec0cca0 Mon Sep 17 00:00:00 2001 From: Samuel Plumppu <6125097+Greenheart@users.noreply.github.com> Date: Mon, 2 Mar 2026 12:53:59 +0100 Subject: [PATCH] fix: Clarify the purpose of regex that didn't match the full alphanumeric character set. This changes no behaviour, but ensures the naming is consistent with actual usage. The reason for splitting the alphanumeric regex into `numeric` and `lettersAndCharacters` is likely to allow reusing the regex for numeric QR codes. --- lib/core/regex.js | 4 ++-- lib/core/segments.js | 4 ++-- test/unit/core/regex.test.js | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/core/regex.js b/lib/core/regex.js index 9dd13a42..c23b903d 100644 --- a/lib/core/regex.js +++ b/lib/core/regex.js @@ -1,5 +1,5 @@ const numeric = '[0-9]+' -const alphanumeric = '[A-Z $%*+\\-./:]+' +const lettersAndCharacters = '[A-Z $%*+\\-./:]+' let kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + @@ -12,7 +12,7 @@ exports.KANJI = new RegExp(kanji, 'g') exports.BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g') exports.BYTE = new RegExp(byte, 'g') exports.NUMERIC = new RegExp(numeric, 'g') -exports.ALPHANUMERIC = new RegExp(alphanumeric, 'g') +exports.LETTERS_AND_CHARACTERS = new RegExp(lettersAndCharacters, 'g') const TEST_KANJI = new RegExp('^' + kanji + '$') const TEST_NUMERIC = new RegExp('^' + numeric + '$') diff --git a/lib/core/segments.js b/lib/core/segments.js index ba8be178..a0cf811e 100644 --- a/lib/core/segments.js +++ b/lib/core/segments.js @@ -50,7 +50,7 @@ function getSegments (regex, mode, str) { */ function getSegmentsFromString (dataStr) { const numSegs = getSegments(Regex.NUMERIC, Mode.NUMERIC, dataStr) - const alphaNumSegs = getSegments(Regex.ALPHANUMERIC, Mode.ALPHANUMERIC, dataStr) + const letterAndCharacterSegs = getSegments(Regex.LETTERS_AND_CHARACTERS, Mode.ALPHANUMERIC, dataStr) let byteSegs let kanjiSegs @@ -62,7 +62,7 @@ function getSegmentsFromString (dataStr) { kanjiSegs = [] } - const segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs) + const segs = numSegs.concat(letterAndCharacterSegs, byteSegs, kanjiSegs) return segs .sort(function (s1, s2) { diff --git a/test/unit/core/regex.test.js b/test/unit/core/regex.test.js index f4cd8a1f..1aa2fc0e 100644 --- a/test/unit/core/regex.test.js +++ b/test/unit/core/regex.test.js @@ -5,8 +5,8 @@ test('Regex', function (t) { t.ok(Regex.NUMERIC instanceof RegExp, 'Should export a regex for NUMERIC') - t.ok(Regex.ALPHANUMERIC instanceof RegExp, - 'Should export a regex for ALPHANUMERIC') + t.ok(Regex.LETTERS_AND_CHARACTERS instanceof RegExp, + 'Should export a regex for LETTERS_AND_CHARACTERS') t.ok(Regex.BYTE instanceof RegExp, 'Should export a regex for BYTE')