-
Notifications
You must be signed in to change notification settings - Fork 303
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 1120 1256 from NSS5.1.6 ressource-mapper #1280
Conversation
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.
Thanks, the main idea of the fix looks good (distinguishing between isFolder
and searchIndex
).
Still needs unit tests though on the ResourceMapper
side.
lib/resource-mapper.js
Outdated
@@ -7,7 +7,7 @@ const HTTPError = require('./http-error') | |||
|
|||
/* | |||
* A ResourceMapper maintains the mapping between HTTP URLs and server filenames, | |||
* following the principles of the “sweet spot” discussed in | |||
* following the principles of the “sweet spot� discussed in |
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.
encoding issue
lib/resource-mapper.js
Outdated
// Parse the URL and find the base file path | ||
const { pathname, hostname } = this._parseUrl(url) | ||
const filePath = this.resolveFilePath(hostname, decodeURIComponent(pathname)) | ||
if (filePath.indexOf('/..') >= 0) { | ||
throw new Error('Disallowed /.. segment in URL') | ||
} | ||
let isIndex = searchIndex && filePath.endsWith('/') | ||
let isFolder = filePath.endsWith('/') |
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.
Is this actually an assumption we can make? Or should it be passed in explicitly as a parameter?
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.
const
?
lib/resource-mapper.js
Outdated
if (match === undefined) {throw new HTTPError(404, `Resource not found: ${pathname}`)} | ||
|
||
// Check if the index file exists | ||
} else if (isIndex && files.includes(this._indexFilename)) { |
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.
isIndex
should be searchIndex
here
lib/resource-mapper.js
Outdated
// Parse the URL and find the base file path | ||
const { pathname, hostname } = this._parseUrl(url) | ||
const filePath = this.resolveFilePath(hostname, decodeURIComponent(pathname)) | ||
if (filePath.indexOf('/..') >= 0) { | ||
throw new Error('Disallowed /.. segment in URL') | ||
} | ||
let isIndex = searchIndex && filePath.endsWith('/') | ||
let isFolder = filePath.endsWith('/') | ||
let isIndex = searchIndex && isFolder |
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 this variable can be dropped (as per my comment below).
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.
Not being a coder. I need help.
-
L127 OK
searchIndex
and drop ofisIndex
in L95 -
L94 do you want to replace
isFolder
byfilePath.endsWith('/')
everywhere it's used or to use an other variable name or to pass a parameter (this test was already used)
(The code allready used the endsWith('/') I would like to avoid at this stage to add a new parameter and push a test on allmapUrlToFile
calls) -
I suppose I have to modify the tests that errored N°5 and 6 in travis due to my modifications. It may relates to explicitely set searchIndex value to true.
How can I send my modifications : as a new PR or something else (I have never done it)
Sorry for my deeply need of help
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.
Not being a coder.
This is good stuff though 👍
L94, okay, leave as is.
How can I send my modifications
You just push another commit to the branch you have created. So just keep pushing to your own master
branch, and they will end up here. Don't hesitate to ask if you're uncertain, happy to explain!
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.
ressource-mapper tests
I have a problem with that test :
itMapsUrl(mapper, 'a URL ending with a slash to a folder when index is skipped',
{
url: 'http://localhost/space/',
contentType: 'application/octet-stream',
createIfNotExists: true,
searchIndex: false
},
{
path: `${rootPath}space/`,
contentType: 'application/octet-stream'
})
Is it a use case ?
It creates a folder with contentType.
In all tests cases it is the only case where a folder is created. I missed this behaviour.
If yes I need to slightly modify my code and I did not found where it is used (PUT, PATCH, POST)
Can you confirm.
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.
Is tthere no code calling it with createIfNotExists: true
and searchIndex: false
? Because this code might be used to create a folder.
fix finally Ok and tested on pod with docker and in using solid-ide. The tests cases where a bit complex to elaborate. I tried to make them clean enough to understand. I reintroduced
nota : I checked with notepad++ and I confirm that there is no code calling |
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.
Minor comments; tests are still failing though, seems like test changes were not incorporated.
lib/resource-mapper.js
Outdated
// create a new folder | ||
if (!searchIndex && isFolder) { | ||
// else create a new file | ||
} else { |
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.
if
statement with empty body is to be avoided
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 shall replace with
if ((!searchIndex && isFolder) === false) {
What shall I do with the tests ? Are the errors related to the fix ?
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.
Or just if (searchIndex !! !isFolder)
.
Tests are indeed related; some behavior is changed, so should be updated. I think the behavior is correct though.
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 suppose you meant if (searchIndex || !isFolder)
which do not cover searchIndex: false
and isFolder: false
which would allow to create a file without contentType control or read without check it exists.
I think there are missing tests that should cover the case :
itMapsUrl(mapper, "a URL with a bogus extension that doesn't match the content type",
{
url: 'http://localhost/space/foo.ttl',
contentType: 'text/html',
createIfNotExists: true,
searchIndex: false
},
{
path: `${rootPath}space/foo.ttl$.html`,
contentType: 'text/html'
})
and cases without createIfNotExists
.
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 suppose you meant
if (searchIndex || !isFolder)
No, I meant that if ((!searchIndex && isFolder) === false) {
is written more simply as if (searchIndex || !isFolder)
.
Case looks good.
requested changes made. |
But are the timeouts causes by the changes, or where they present before? |
I close the pull request to begin a new one to check travis at every step |
@RubenVerborgh @jaxoncreed
fix issues #1120 #1256 from NSS5.1.6
ressource-mapper
(should replace PR #1260 )function mapUrlToFile
:( it seems that for some reason using
searchIndex = true
in function definition mapUrlToFile causes problem. searchIndex is not updated when calling directly mapUrlToFile - but updated if called through an other function like ldp.get or get.js )-- createIfNotExists = true : replace isIndex by isFolder (I suppose not needed use of searchIndex = true)
-- createIfNotExists = false : reorganization of tests around
isFolder
andisIndex
in lieu ofsearchIndex
andisIndex
get.js
modified along PR Resource-mapper now considers content type when inserting index.html #1260 (use case not clear to me)ldp.js
modified to avoid double extension when usingslug with extension
Tested on a pod (created with docker) and solid-Ide.
There is a remaining problem : Pod connexion to root needs login (?? something with allow.js)