piqnt / svgexport

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

Fix Windows paths by using URL constructor #86

Open silverwind opened 4 years ago

silverwind commented 4 years ago

The URL constructor seems to correctly handle both Windows and Unix-style paths so should be the preferred way to generate File-URIs. This does require Node.js 10 or greater where the URL global was introduced.

Some quick tests demonstrating the output:

> String(new URL(`file://c:\\a\\b.svg`))
'file:///c:/a/b.svg'
> String(new URL(`file:///a/b.svg`))
'file:///a/b.svg'

Can also confirm this works on Windows and Linux.