Skip to content

Commit 0e3fb54

Browse files
committedFeb 20, 2022
[fix] Strip all control characters from the beginning of the URL
1 parent 61864a8 commit 0e3fb54

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed
 

‎index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var required = require('requires-port')
66
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//
77
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\\/]+)?([\S\s]*)/i
88
, windowsDriveLetter = /^[a-zA-Z]:/
9-
, whitespace = /^[ \f\n\r\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/;
9+
, whitespace = /^[\x00-\x20\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/;
1010

1111
/**
1212
* Trim a given string.

‎test/test.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ describe('url-parse', function () {
4747
assume(parse.trimLeft).is.a('function');
4848
});
4949

50-
it('removes whitespace on the left', function () {
51-
assume(parse.trimLeft(' lol')).equals('lol');
50+
it('removes control characters on the left', function () {
51+
var i = 0;
52+
var prefix = ''
53+
54+
for (; i < 33; i++) {
55+
prefix = String.fromCharCode(i);
56+
assume(parse.trimLeft(prefix + prefix +'lol')).equals('lol');
57+
}
5258
});
5359

5460
it('calls toString on a given value', function () {

0 commit comments

Comments
 (0)
Please sign in to comment.