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

Special characters (such as spaces) in paths are not escaped #84

Open
jamesallardice opened this issue May 25, 2016 · 3 comments
Open

Comments

@jamesallardice
Copy link

When intercepting a request and serving a file from the local filesystem as a response, spaces in the path to that file cause problems.

This can be worked around quite easily by e.g. URI encoding the value passed to cycle.serve but it may be something that the method itself can do.

Any thoughts? I'd be happy to get a PR open for this if necessary.

@greim
Copy link
Owner

greim commented May 25, 2016

What sort of problems? I don't think it should URL-encode the value since it would cause already-encoded values to get double-encoded. A routine to encode just invalid characters might work, but it seems odd to me that the browser would pass along invalid chars to Hoxy in the first place.

@jamesallardice
Copy link
Author

For example (very basic simplified):

const fixturePath = '/Users/somebody/some path with spaces/fixtures/fixture.json';
const proxy = hoxy.createServer({ /*... reverse proxy settings ... */ });
proxy.intercept({ phase: 'request' /* ... */ }, (req, res, cycle) => cycle.serve(fixturePath));

When that path gets through to the static file server it fails to find the file unless the spaces are URI encoded. In my case the value of fixturePath is generated (from e.g. __dirname). We ran into this problem when someone with spaces in a directory name somewhere in their structure tried to run the code in question.

@greim
Copy link
Owner

greim commented May 25, 2016

Ah okay. So yeah it isn't the browser generating the URL in this case. Re-reading that code, I'm remembering now issues surrounding path differences on Windows versus other platforms. Presumably the toUrlPath() method will need to sanitize its output by escaping invalid characters.

Happy to accept a PR for this!

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

No branches or pull requests

2 participants