Skip to content

Commit

Permalink
Snyk js braces 6838727 (#40)
Browse files Browse the repository at this point in the history
* Remove maxSymbols from README

* Revert "Merge pull request #37 from coderaiser/fix/vulnerability"

This reverts commit a5851e5, reversing
changes made to 98414f9.

* Lower defaultLength to 10000
  • Loading branch information
AaronMoat authored May 21, 2024
1 parent 190510f commit 415d660
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 79 deletions.
2 changes: 1 addition & 1 deletion .verb.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ console.log(braces.expand('a{b}c'));

**Type**: `Number`

**Default**: `65,536`
**Default**: `10,000`

**Description**: Limit the length of the input string. Useful when the input string is generated or your application allows users to pass a string, et cetera.

Expand Down
14 changes: 1 addition & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,26 +178,14 @@ console.log(braces.expand('a{b}c'));

**Type**: `Number`

**Default**: `65,536`
**Default**: `10,000`

**Description**: Limit the length of the input string. Useful when the input string is generated or your application allows users to pass a string, et cetera.

```js
console.log(braces('a/{b,c}/d', { maxLength: 3 })); //=> throws an error
```

### options.maxSymbols

**Type**: `Number`

**Default**: `1024`

**Description**: Limit the count of unique symbols the input string.

```js
console.log(braces('a/{b,c}/d', { maxSymbols: 2 })); //=> throws an error
```

### options.expand

**Type**: `Boolean`
Expand Down
3 changes: 1 addition & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
'use strict';

module.exports = {
MAX_LENGTH: 1024 * 64,
MAX_SYMBOLS: 1024,
MAX_LENGTH: 10000,

// Digits
CHAR_0: '0', /* 0 */
Expand Down
62 changes: 21 additions & 41 deletions lib/parse.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
'use strict';

const stringify = require('./stringify');
const {isCorrectBraces, validateInput} = require('./validate-input');

/**
* Constants
*/

const {
MAX_LENGTH,
MAX_SYMBOLS,
CHAR_BACKSLASH, /* \ */
CHAR_BACKTICK, /* ` */
CHAR_COMMA, /* , */
Expand All @@ -36,11 +34,6 @@ const parse = (input, options = {}) => {
}

let opts = options || {};

validateInput(input, {
maxSymbols: opts.maxSymbols || MAX_SYMBOLS,
});

let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
if (input.length > max) {
throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
Expand Down Expand Up @@ -311,43 +304,30 @@ const parse = (input, options = {}) => {
push({ type: 'text', value });
}

flattenBlocks(stack)
markImbalancedBraces(ast);
push({ type: 'eos' });

return ast;
};

module.exports = parse;

function markImbalancedBraces({nodes}) {
// Mark imbalanced braces and brackets as invalid
for (const node of nodes) {
if (!node.nodes && !node.invalid) {
if (node.type === 'open') node.isOpen = true;
if (node.type === 'close') node.isClose = true;
if (!node.nodes) node.type = 'text';

node.invalid = true;
}

delete node.parent;
delete node.prev;
}
}

function flattenBlocks(stack) {
let block;
do {
block = stack.pop();

if (block.type === 'root')
continue;
if (block.type !== 'root') {
block.nodes.forEach(node => {
if (!node.nodes) {
if (node.type === 'open') node.isOpen = true;
if (node.type === 'close') node.isClose = true;
if (!node.nodes) node.type = 'text';
node.invalid = true;
}
});

// get the location of the block on parent.nodes (block's siblings)
let parent = stack.at(-1);
let index = parent.nodes.indexOf(block);
// replace the (invalid) block with its nodes
parent.nodes.splice(index, 1, ...block.nodes);
// get the location of the block on parent.nodes (block's siblings)
let parent = stack[stack.length - 1];
let index = parent.nodes.indexOf(block);
// replace the (invalid) block with it's nodes
parent.nodes.splice(index, 1, ...block.nodes);
}
} while (stack.length > 0);
}

push({ type: 'eos' });
return ast;
};

module.exports = parse;
12 changes: 0 additions & 12 deletions lib/validate-input.js

This file was deleted.

10 changes: 0 additions & 10 deletions test/braces.parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ describe('braces.parse()', () => {
let MAX_LENGTH = 1024 * 64;
assert.throws(() => parse('.'.repeat(MAX_LENGTH + 2)));
});
it('should throw an error when symbols exceeds max symbols count default', () => {
let SYMBOLS= 1024;
assert.throws(() => parse('.'.repeat(MAX_SYMBOLS * 2)));
});
it('should throw an error when symbols exceeds max symbols count ', () => {
let SYMBOLS= 2;
assert.throws(() => parse('...', {
maxSymbols: 2,
}));
});
});

describe('valid', () => {
Expand Down

3 comments on commit 415d660

@moeje2024
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FEDERAL INDIAN LAW ORDINANCE supra ENHANCEMENTS DigHistEncLEd Contents, Tabling Of Autonomous IHS~NIL & NAI COMMUNITY CENTERS LIFELINES IN AI FOR BIOMETRICAL TELEMETRY HEALTH PERSONAL BODILY HYGENIAL CONJUGAL CONGENIAL Cooperation Agreement Significant Person Care Giver Performance Copyright Duces Tecum of 17 U.S. CODE OF LAW ANN SVC PCKTPRT sec'n 103 107 113 121 as is(,) of sec'n 512 (;&) as to follo(.) sec'n 1201 & 1202 Parity Of Ex Compoi Mentis , Guardianem Ad Litem of 30 AM JUR 2d RADIOLOGICAL PSYCHIATRIC TAMPERING PSYCHOLOGICAL BIGAMY SHAM BITCHERIES BASTARDIES (:|:) ׶'¶× (:|:) automating integrated NAVAJO CODING cryptology aligning with DE VINCI CODEC bodily DNA gray tissue 0.1 grayscale ©`°? USSC ECF=PACER RES IN REM COBELLE , IN RE EVE GOOD BEAR V SALAZAR NORTON KEEFER BABBITT Vis Prohibitivam of SexoMania SexoPhony SexoMedias Mala Praxiis Quare Clausei Fregitis Of Health Hygiene Conjugal Congeniality AI automating integrated graphics realtiming interactive ECIP Biometrical Telemetry En Certioraris Ad Certiorem of (AI) e'USCFA cs no 99-12391-HH OUT OF TIME (,) DE NOVO (Com)Plaintiff WarrenDerek Hollinger Vs USA ET_AL & ALL OTHERs Infra Esse REDRESS OF GRIEVANCES REVERSE DEMAND FOR PROSECUTION FOR FAILURE ADHERE TO MY DEMAND THAT ALL INFRINGERS & INFRINGEMENT CEASE & DESIST IMMEDIATELY PERMANENTLY Ad Infinitum whether Montagery Malo Ex Delictis of REVERSE ENGINEERING Malo Dolo of Heinous Crime Prohibited Exposure to Malam Delictam of Sexological Offensive False Personation to expose perscutory hatred and hate crimes Mayhem Mutilation Diplomatic Extortionisms Inanimating Fabrication Of Persecutory Adversity S&M sabotage disparagements forced submission & revenge for nonsubmission to pervertrixyling covertures ?/? USSC CERTIFIED QUESTION RULE cs collateral en escrowanciis MCGIRT V STATE Eo Instantis (;&) Ad Infinitum Perpetual Disposition Testomy & Perpetual Evidences Rule Ed'n Of Realtiming Law Ad Ibidis !!!!
2024 All rights reserved unreleased exclusive by me pseudonym LttlShwr pseudodatam serial autobiography copyright ownor Id Affix'd Print Affix Origi Affix ( anil. ) !!!!

@moeje2024
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@moeje2024
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/parse.js

Please sign in to comment.