fix 1120 1256 from NSS5.1.6 ressource-mapper - #1280
Conversation
RubenVerborgh
left a comment
There was a problem hiding this comment.
Thanks, the main idea of the fix looks good (distinguishing between isFolder and searchIndex).
Still needs unit tests though on the ResourceMapper side.
| /* | ||
| * 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 |
| throw new Error('Disallowed /.. segment in URL') | ||
| } | ||
| let isIndex = searchIndex && filePath.endsWith('/') | ||
| let isFolder = filePath.endsWith('/') |
There was a problem hiding this comment.
Is this actually an assumption we can make? Or should it be passed in explicitly as a parameter?
| 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.
isIndex should be searchIndex here
| } | ||
| let isIndex = searchIndex && filePath.endsWith('/') | ||
| let isFolder = filePath.endsWith('/') | ||
| let isIndex = searchIndex && isFolder |
There was a problem hiding this comment.
I think this variable can be dropped (as per my comment below).
There was a problem hiding this comment.
Not being a coder. I need help.
-
L127 OK
searchIndexand drop ofisIndexin L95 -
L94 do you want to replace
isFolderbyfilePath.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 allmapUrlToFilecalls) -
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.
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.
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.
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 |
RubenVerborgh
left a comment
There was a problem hiding this comment.
Minor comments; tests are still failing though, seems like test changes were not incorporated.
| // create a new folder | ||
| if (!searchIndex && isFolder) { | ||
| // else create a new file | ||
| } else { |
There was a problem hiding this comment.
if statement with empty body is to be avoided
There was a problem hiding this comment.
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.
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.
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.
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 = truein 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
isFolderandisIndexin lieu ofsearchIndexandisIndexget.jsmodified along PR Resource-mapper now considers content type when inserting index.html #1260 (use case not clear to me)ldp.jsmodified to avoid double extension when usingslug with extensionTested on a pod (created with docker) and solid-Ide.
There is a remaining problem : Pod connexion to root needs login (?? something with allow.js)