From 0e3fb542d60ddbf6933f22eb9b1e06e25eaa5b63 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 20 Feb 2022 08:48:07 +0100 Subject: [PATCH] [fix] Strip all control characters from the beginning of the URL --- index.js | 2 +- test/test.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index c5a2a11..aa71e5d 100644 --- a/index.js +++ b/index.js @@ -6,7 +6,7 @@ var required = require('requires-port') , slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\// , protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i , windowsDriveLetter = /^[a-zA-Z]:/ - , whitespace = /^[ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/; + , whitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/; /** * Trim a given string. diff --git a/test/test.js b/test/test.js index ab2c6c3..f85ebb6 100644 --- a/test/test.js +++ b/test/test.js @@ -47,8 +47,14 @@ describe('url-parse', function () { assume(parse.trimLeft).is.a('function'); }); - it('removes whitespace on the left', function () { - assume(parse.trimLeft(' lol')).equals('lol'); + it('removes control characters on the left', function () { + var i = 0; + var prefix = '' + + for (; i < 33; i++) { + prefix = String.fromCharCode(i); + assume(parse.trimLeft(prefix + prefix +'lol')).equals('lol'); + } }); it('calls toString on a given value', function () {