-
Notifications
You must be signed in to change notification settings - Fork 304
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
Changes from 5 commits
d2f1d85
bddb196
be1d446
5cef7dc
7e3153d
60cc593
2e39d61
5515d75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* https://www.w3.org/DesignIssues/HTTPFilenameMapping.html | ||
* | ||
* This class implements this mapping in a single place | ||
|
@@ -91,22 +91,28 @@ class ResourceMapper { | |
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Not being a coder. I need help.
How can I send my modifications : as a new PR or something else (I have never done it) 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 is good stuff though 👍 L94, okay, leave as is.
You just push another commit to the branch you have created. So just keep pushing to your own 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. ressource-mapper tests
Is it a use case ? Can you confirm. 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. Is tthere no code calling it with |
||
|
||
// Create the path for a new file | ||
let path | ||
if (createIfNotExists) { | ||
path = filePath | ||
// Append index filename if needed | ||
if (isIndex) { | ||
if (contentType !== this._indexContentType) { | ||
throw new Error(`Index file needs to have ${this._indexContentType} as content type`) | ||
} | ||
path += this._indexFilename | ||
} | ||
// If the extension is not correct for the content type, append the correct extension | ||
if (searchIndex && this._getContentTypeByExtension(path) !== contentType) { | ||
path += `$${contentType in extensions ? `.${extensions[contentType][0]}` : '.unknown'}` | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more.
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. I shall replace with
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 commentThe reason will be displayed to describe this comment to others. Learn more. Or just 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 commentThe reason will be displayed to describe this comment to others. Learn more. I suppose you meant I think there are missing tests that should cover the case :
and cases without 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.
No, I meant that Case looks good. |
||
// Append index filename if needed | ||
if (isIndex) { | ||
RubenVerborgh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (contentType !== this._indexContentType) { | ||
throw new Error(`Index file needs to have ${this._indexContentType} as content type`) | ||
} | ||
path += this._indexFilename | ||
} | ||
// If the extension is not correct for the content type, append the correct extension | ||
if (this._getContentTypeByExtension(path) !== contentType) { | ||
path += `$${contentType in extensions ? `.${extensions[contentType][0]}` : '.unknown'}` | ||
} | ||
} | ||
// Determine the path of an existing file | ||
} else { | ||
|
@@ -116,23 +122,15 @@ class ResourceMapper { | |
|
||
// Find a file with the same name (minus the dollar extension) | ||
let match = '' | ||
if (searchIndex) { | ||
const files = await this._readdir(folder) | ||
// Search for files with the same name (disregarding a dollar extension) | ||
if (!isIndex) { | ||
match = files.find(f => this._removeDollarExtension(f) === filename) | ||
// Check if the index file exists | ||
} else if (files.includes(this._indexFilename)) { | ||
match = this._indexFilename | ||
} | ||
} | ||
// Error if no match was found (unless URL ends with '/', then fall back to the folder) | ||
if (match === undefined) { | ||
if (isIndex) { | ||
match = '' | ||
} else { | ||
throw new HTTPError(404, `Resource not found: ${pathname}`) | ||
} | ||
const files = await this._readdir(folder) | ||
// Search for files with the same name (disregarding a dollar extension) | ||
if (!isFolder) { | ||
match = files.find(f => this._removeDollarExtension(f) === filename) | ||
if (match === undefined) {throw new HTTPError(404, `Resource not found: ${pathname}`)} | ||
|
||
// Check if the index file exists | ||
} else if (searchIndex && files.includes(this._indexFilename)) { | ||
match = this._indexFilename | ||
} | ||
path = `${folder}${match}` | ||
contentType = this._getContentTypeByExtension(match) | ||
|
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
?