piqnt / svgexport

SVG to PNG/JPEG command-line tool and Node.js module
927 stars 85 forks source link

Replace `split(/\s+/)` to allow for spaces in file names & paths when using datafile #91

Open asp55 opened 3 years ago

asp55 commented 3 years ago

Replace split(/\s+/) with match(/\w+|"[^"]+"|'[^']+'/g).map(v=>v.replace(/"([^"]+)"|'([^']+)'/g,"$1$2")) to split only on spaces not wrapped in quotes to allow for spaces in file names & paths

shakiba commented 3 years ago

Thanks, could we use a library instead?

asp55 commented 3 years ago

Not sure I follow what you'd be using a library to do.

The existing use of split(/\s+/) in splitParams function makes it so that if you're using a datafile to do your configuration and you have a space in a file path, it'll split that as well.

In the replacement line: match(/\w+|"[^"]+"|'[^']+'/g) splits only on spaces that aren't wrapped in quotes. And then the map(v=>v.replace(/"([^"]+)"|'([^']+)'/g,"$1$2")) removes those wrapping quotes