Skip to content

Commit

Permalink
Merge pull request #137 from ChALkeR/320159-part-1
Browse files Browse the repository at this point in the history
320159 fixes part 1
  • Loading branch information
3rd-Eden committed Apr 5, 2019
2 parents c92567b + 79c7c54 commit 187c172
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions index.js
Expand Up @@ -415,10 +415,12 @@ function isSafe(userAgent) {
var consecutive = 0
, code = 0;

if (userAgent.length > 1000) return false;

for (var i = 0; i < userAgent.length; i++) {
code = userAgent.charCodeAt(i);
// numbers between 0 and 9, letters between a and z
if ((code >= 48 && code <= 57) || (code >= 97 && code <= 122)) {
// numbers between 0 and 9, letters between a and z, spaces and control
if ((code >= 48 && code <= 57) || (code >= 97 && code <= 122) || code <= 32) {
consecutive++;
} else {
consecutive = 0;
Expand All @@ -443,6 +445,10 @@ function isSafe(userAgent) {
* @api public
*/
exports.parse = function parse(userAgent, jsAgent) {
if (userAgent && userAgent.length > 1000) {
userAgent = userAgent.substring(0, 1000);
}

if (!userAgent || !isSafe(userAgent)) return new Agent();

var length = agentparserslength
Expand Down

0 comments on commit 187c172

Please sign in to comment.