From ce2eb1e09acdd5adb8a35485ccf635a73b84e5b9 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Sat, 6 Jan 2024 13:21:18 -0400 Subject: validators, test: don't include line break in surroundings --- src/data/things/validators.js | 4 ++-- test/unit/data/things/validators.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/data/things/validators.js b/src/data/things/validators.js index b462be47..f9910364 100644 --- a/src/data/things/validators.js +++ b/src/data/things/validators.js @@ -447,10 +447,10 @@ const illegalCharactersInContent = .join(''); const legalContentNearEndRegexp = - new RegExp(`[^${illegalCharactersInContent}]+$`); + new RegExp(`[^\n${illegalCharactersInContent}]+$`); const legalContentNearStartRegexp = - new RegExp(`^[^${illegalCharactersInContent}]+`); + new RegExp(`^[^\n${illegalCharactersInContent}]+`); const trimWhitespaceNearBothSidesRegexp = /^ +| +$/gm; diff --git a/test/unit/data/things/validators.js b/test/unit/data/things/validators.js index fd86c131..11134a90 100644 --- a/test/unit/data/things/validators.js +++ b/test/unit/data/things/validators.js @@ -168,7 +168,7 @@ t.test('isCommentary', t => { }); t.test('isContentString', t => { - t.plan(11); + t.plan(12); t.ok(isContentString(`Hello, world!`)); t.ok(isContentString(`Hello...\nWorld!`)); @@ -209,6 +209,19 @@ t.test('isContentString', t => { ]), ])); + quickThrows( + `It's go-\u200bin',\n` + + `\u200bIt's goin',\u200b\n` + + `\u200b\u200bIt's going!`, + new AggregateError([ + new AggregateError([ + new TypeError(`Delete "\u200b" (zero-width space) between "go-" and "in'" (line: 1, col: 9)`), + new TypeError(`Delete "\u200b" (zero-width space) before "It'" (line: 2, col: 1)`), + new TypeError(`Delete "\u200b" (zero-width space) after "n'," (line: 2, col: 13)`), + new TypeError(`Delete "\u200b\u200b" (zero-width space) before "It'" (line: 3, col: 1)`), + ]), + ])); + quickThrows( ` Room at the start.`, new AggregateError([ -- cgit 1.3.0-6-gf8a5