Repository navigation
Fix URI encoding in file listing and decoding to get file names #471
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -546,6 +546,29 @@ describe('HTTP APIs', function () { | |
| .expect(200, done) | ||
| }) | ||
|
|
||
| it('should create a container with a name hex decoded from the slug', (done) => { | ||
| let containerName = 'Film%4011' | ||
| let expectedDirName = '/post-tests/Film@11/' | ||
| server.post('/post-tests/') | ||
| .set('slug', containerName) | ||
| .set('content-type', 'text/turtle') | ||
| .set('link', '<http://www.w3.org/ns/ldp#BasicContainer>; rel="type"') | ||
| .expect(201) | ||
| .end((err, res) => { | ||
| if (err) return done(err) | ||
| try { | ||
| assert.equal(res.headers.location, expectedDirName, | ||
| 'Uri container names should be encoded') | ||
| let createdDir = fs.statSync(path.join(__dirname, 'resources', expectedDirName)) | ||
| assert(createdDir.isDirectory(), 'Container should have been created') | ||
| } catch (err) { | ||
| return done(err) | ||
| } | ||
| done() | ||
| }) | ||
| }) | ||
|
|
||
| /* No, URLs are NOT ex-encoded to make filenames -- the other way around. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should be changed to test for a 400 error response, per our conversation. |
||
| it('should create a container with a url name', (done) => { | ||
| let containerName = 'https://example.com/page' | ||
| let expectedDirName = '/post-tests/https%3A%2F%2Fexample.com%2Fpage/' | ||
|
|
@@ -574,6 +597,7 @@ describe('HTTP APIs', function () { | |
| .expect('content-type', /text\/turtle/) | ||
| .expect(200, done) | ||
| }) | ||
| */ | ||
|
|
||
| after(function () { | ||
| // Clean up after POST API tests | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -109,6 +109,7 @@ describe('LDP', function () { | |
| }) | ||
| }) | ||
| describe('listContainer', function () { | ||
| /* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind deleting the test, instead of commenting out? |
||
| it('should inherit type if file is .ttl', function (done) { | ||
| write('@prefix dcterms: <http://purl.org/dc/terms/>.' + | ||
| '@prefix o: <http://example.org/ontology>.' + | ||
|
|
@@ -145,7 +146,7 @@ describe('LDP', function () { | |
| done() | ||
| }) | ||
| }) | ||
|
|
||
| */ | ||
| it('should not inherit type of BasicContainer/Container if type is File', function (done) { | ||
| write('@prefix dcterms: <http://purl.org/dc/terms/>.' + | ||
| '@prefix o: <http://example.org/ontology>.' + | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we're going to run into problems with this approach. What if the file (or container) was uploaded as already uri-encoded? Say, for example, it was uploaded as
hello%20world.ttl? And exists on disk ashello%20world.ttl. If you then issue a GET on it and this methoduriToFilename()is invoked, it will try and look for the filenamehello world.ttland not find it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is especially relevant given the recent PR #469, which url-encodes container names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a file is uploaded, any filename is URI-encoded to form the URI.
If the file "hello world.ttl" exists then the resource "hello%20world.ttl" exists already too.
If there is a file on disk called "hello%20world.ttl" then there is corresponding LDP resource "hello%2520world.ttl"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reversible mapping. The file world is self-consistent. The URL world is self-consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In thinking about this, I realize we still have an open issue where we don't URI-encode file names on PUT. (Only container names). So it's still possible for people to try and create files with names that are illegal as far as the OS/filesystem is concerned.
If we fix this issue (and enforce URI-encoding of filenames on PUT and POST), then there is no need to uri-encode them on listing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A goal of this project is to be able to export existing files system users have. This means hex encoding things like space which are not allowed in URLs. A Windows or Mac Documents or Music folder should be be able to export into Solid in a useful way.
It is NOT a goal to be able to allow clients to put files with characters which are typically illegal in a file system, like say colon, slash, or vertical bar. I think we could return an error when a PUT or PATCH tries to do that (by hex encoding them in a URL). I don't see any value in allowing this characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would this export process work? The existing files would arrive on a Solid server via PUTs and POSTs, right? Which means their filenames would be safely encoded.
What would you like to see as the behavior when users/developers inevitably try to PUT or POST those kind of file names (illegal in file system)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add * ? \
?
Or wait until the file system objects?
Example use case: I want to copy my entire Mac home folder into a solid server to sync it with other macs