From 1b7e40b40535a32ec0ee22f7dae238cc7d2c39c0 Mon Sep 17 00:00:00 2001 From: Tim Hitchins Date: Thu, 4 Jul 2024 15:41:42 +0100 Subject: [PATCH 1/2] #48 add test cases for set expansion with a range operator --- test/bash-expanded-sets.js | 89 +++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/test/bash-expanded-sets.js b/test/bash-expanded-sets.js index b5a40cc..8e35455 100644 --- a/test/bash-expanded-sets.js +++ b/test/bash-expanded-sets.js @@ -222,7 +222,94 @@ describe('bash - expanded brace sets', () => { ['f{x,y{{g}}h', {}, ['f{x,y{{g}}h']], ['a{b{c{d,e}f{x,y{}g}h', {}, ['a{b{cdfxh', 'a{b{cdfy{}gh', 'a{b{cefxh', 'a{b{cefy{}gh']], ['f{x,y{}g}h', {}, ['fxh', 'fy{}gh']], - ['z{a,b{,c}d', {}, ['z{a,bd', 'z{a,bcd']] + ['z{a,b{,c}d', {}, ['z{a,bd', 'z{a,bcd']], + + 'should expand sets containing the range operator', + + ['{..a,b}', {}, ['..a', 'b']], + ['{b,..a}', {}, ['b', '..a']], + ['{a..,b}', {}, ['a..', 'b']], + ['{...,b}', {}, ['...', 'b']], + ['{a,..,b}', {}, ['a', '..', 'b']], + ['..{a,b}', {}, ['..a', '..b']], + ['{{..,..},a,b}', {}, ['..', '..', 'a', 'b']], + ['{{{..,..}a,b}c,d}', {}, ['..ac', '..ac', 'bc', 'd']], + ['..{..,{..,{..,..}a,b}c,d}', {}, ['....', '....c', '....ac', '....ac', '..bc', '..d']], + ['..', {}, ['..']], + ['{,..}', {}, ['', '..']], + ['{..,}', {}, ['..', '']], + ['{..,..,..}', {}, ['..', '..', '..']], + ['{...,..,..}', {}, ['...', '..', '..']], + ['{..,...,..}', {}, ['..', '...', '..']], + ['{./../.,../../}', {}, ['./../.', '../../']], + ['{../../../,../../}', {}, ['../../../', '../../']], + ['{...,...,...}', {}, ['...', '...', '...']], + ['{.,..,.}', {}, ['.', '..', '.']], + [',{..,..,.},', {}, [',..,', ',..,', ',.,']], + ['{1..2,3..4}', {}, ['1..2', '3..4']], + ['{..2,3..4}', {}, ['..2', '3..4']], + ['{1..,2}', {}, ['1..', '2']], + ['{1..,..2..,..3}', {}, ['1..', '..2..', '..3']], + ['..{1..3}', {}, ['..1', '..2', '..3']], + ['..{1..3}{..,..}', {}, ['..1..', '..1..', '..2..', '..2..', '..3..', '..3..']], + + 'should not expand invalid sets containing the range operator', + + ['{..a,b', {}, ['{..a,b']], + ['{b,..a', {}, ['{b,..a']], + ['{a..,b', {}, ['{a..,b']], + ['{...,b', {}, ['{...,b']], + ['{a,..,b', {}, ['{a,..,b']], + ['..{a,b', {}, ['..{a,b']], + ['{{..,..},a,b', {}, ['{..,a,b', '{..,a,b']], + ['{{{..,..}a,b}c,d', {}, ['{..ac,d', '{..ac,d', '{bc,d']], + ['{{{..,..}a,bc,d}', {}, ['{..a', '{..a', '{bc', '{d']], + ['..{..,{..,{..,..}a,b}c,d', {}, ['..{..,..c,d', '..{..,..ac,d', '..{..,..ac,d', '..{..,bc,d']], + ['..', {}, ['..']], + ['{,..', {}, ['{,..']], + ['{..,', {}, ['{..,']], + ['{..,..,..', {}, ['{..,..,..']], + ['{...,..,..', {}, ['{...,..,..']], + ['{..,...,..', {}, ['{..,...,..']], + ['{./../.,../../', {}, ['{./../.,../../']], + ['{../../../,../../', {}, ['{../../../,../../']], + ['{...,...,...', {}, ['{...,...,...']], + ['{.,..,.', {}, ['{.,..,.']], + [',{..,..,.},', {}, [',..,', ',..,', ',.,']], + ['{1..2,3..4', {}, ['{1..2,3..4']], + ['{..2,3..4', {}, ['{..2,3..4']], + ['{1..,2', {}, ['{1..,2']], + ['{1..,..2..,..3', {}, ['{1..,..2..,..3']], + ['..{1..3', {}, ['..{1..3']], + ['..{1..3}{..,..', {}, ['..1{..,..', '..2{..,..', '..3{..,..']], + + ['..a,b}', {}, ['..a,b}']], + ['b,..a}', {}, ['b,..a}']], + ['a..,b}', {}, ['a..,b}']], + ['...,b}', {}, ['...,b}']], + ['a,..,b}', {}, ['a,..,b}']], + ['..a,b}', {}, ['..a,b}']], + ['{..,..},a,b}', {}, ['..,a,b}', '..,a,b}']], + ['{{..,..}a,b}c,d}', {}, ['..ac,d}', '..ac,d}', 'bc,d}']], + ['....,{..,{..,..}a,b}c,d}', {}, ['....,..c,d}', '....,..ac,d}', '....,..ac,d}', '....,bc,d}']], + ['..', {}, ['..']], + [',..}', {}, [',..}']], + ['..,}', {}, ['..,}']], + ['..,..,..}', {}, ['..,..,..}']], + ['...,..,..}', {}, ['...,..,..}']], + ['..,...,..}', {}, ['..,...,..}']], + ['./../.,../../}', {}, ['./../.,../../}']], + ['../../../,../../}', {}, ['../../../,../../}']], + ['...,...,...}', {}, ['...,...,...}']], + ['.,..,.}', {}, ['.,..,.}']], + [',..,..,.},', {}, [',..,..,.},']], + ['1..2,3..4}', {}, ['1..2,3..4}']], + ['..2,3..4}', {}, ['..2,3..4}']], + ['1..,2}', {}, ['1..,2}']], + ['1..,..2..,..3}', {}, ['1..,..2..,..3}']], + ['..1..3}', {}, ['..1..3}']], + ['..1..3}{..,..}', {}, ['..1..3}..', '..1..3}..']], + ]; fixtures.forEach(arr => { From 9a446a82d491685a3b802237bbe11619117d7a5d Mon Sep 17 00:00:00 2001 From: Tim Hitchins Date: Thu, 4 Jul 2024 16:20:37 +0100 Subject: [PATCH 2/2] #48 always reset invalidity of blocks when a comma is encountered --- lib/parse.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/parse.js b/lib/parse.js index 3a6988e..97aac5f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -246,6 +246,7 @@ const parse = (input, options = {}) => { const open = block.nodes.shift(); block.nodes = [open, { type: 'text', value: stringify(block) }]; } + block.invalid = false; push({ type: 'comma', value }); block.commas++;