Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows paths by using URL constructor #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

silverwind
Copy link

@silverwind silverwind commented Jul 24, 2020

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.

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 greated where the `URL` global was intruduced.

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'
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant