Skip to content

Commit

Permalink
[fix] Strip all control characters from the beginning of the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Feb 20, 2022
1 parent 61864a8 commit 0e3fb54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions test/test.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 0e3fb54

Please sign in to comment.