-
Notifications
You must be signed in to change notification settings - Fork 16
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
[FEATURE] Properties File Escaping #214
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
695beb6
[FEATURE] Properties File Escaping
tobiasso85 a5da8ef
Adjust implementation according to latest changes in builder
tobiasso85 c9167d8
Switch to async await to simplify workflow
tobiasso85 e32dabb
adjust config structure change of propertiesFileEncoding in ui5.yml
tobiasso85 9832dd3
Rename encoding property option
tobiasso85 87a7474
Change property name for encoding
tobiasso85 12a47a0
serve resources now uses normal content-type independent from file type
tobiasso85 cd6aea6
fix tests
tobiasso85 04f7f74
Restructure serveResources tests to simplify them
tobiasso85 62dd62f
Add comment to serveResource test
tobiasso85 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,153 @@ | ||
const test = require("ava"); | ||
const sinon = require("sinon"); | ||
const resourceFactory = require("@ui5/fs").resourceFactory; | ||
const serveResourcesMiddleware = require("../../../../lib/middleware/serveResources"); | ||
const writeResource = function(writer, path, size, stringContent) { | ||
const statInfo = { | ||
ino: 0, | ||
ctime: new Date(), | ||
mtime: new Date(), | ||
size: size, | ||
isDirectory: function() { | ||
return false; | ||
} | ||
}; | ||
const resource = resourceFactory.createResource({path, buffer: Buffer.from(stringContent, "latin1"), statInfo}); | ||
// stub resource functionality in order to be able to get the Resource's content. Otherwise it would be drained. | ||
sinon.stub(resource, "getStream").returns({ | ||
pipe: function() { | ||
} | ||
}); | ||
return writer.write(resource).then(() => { | ||
return resource; | ||
}); | ||
}; | ||
const fakeResponse = { | ||
writeHead: function(status, contentType) {}, | ||
getHeader: function(string) {}, | ||
setHeader: function(string, header) {} | ||
}; | ||
|
||
test.afterEach.always((t) => { | ||
sinon.restore(); | ||
}); | ||
|
||
|
||
test.serial("Check if properties file is served properly", (t) => { | ||
t.plan(4); | ||
|
||
const readerWriter = resourceFactory.createAdapter({virBasePath: "/"}); | ||
|
||
return writeResource(readerWriter, "/myFile3.properties", 1024 * 1024, "key=titel\nfame=straße").then((resource) => { | ||
const setStringSpy = sinon.spy(resource, "setString"); | ||
const middleware = serveResourcesMiddleware({ | ||
resources: { | ||
all: readerWriter | ||
}, | ||
tree: { | ||
resources: { | ||
configuration: { | ||
propertiesFileSourceEncoding: "ISO-8859-1" | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const response = fakeResponse; | ||
|
||
const setHeaderSpy = sinon.spy(response, "setHeader"); | ||
const req = { | ||
url: "/myFile3.properties", | ||
headers: {} | ||
}; | ||
const next = function(err) { | ||
throw new Error(`Next callback called with error: ${err.message}`); | ||
}; | ||
return middleware(req, response, next).then((o) => { | ||
return resource.getString(); | ||
}).then((content) => { | ||
t.is(content, `key=titel | ||
fame=stra\\u00dfe`); | ||
t.is(setHeaderSpy.callCount, 2); | ||
t.is(setStringSpy.callCount, 1); | ||
t.is(setHeaderSpy.getCall(0).lastArg, "application/octet-stream"); | ||
}); | ||
}); | ||
}); | ||
|
||
test.serial("Check if properties file is served properly with UTF-8", (t) => { | ||
t.plan(4); | ||
|
||
const readerWriter = resourceFactory.createAdapter({virBasePath: "/"}); | ||
|
||
return writeResource(readerWriter, "/myFile3.properties", 1024 * 1024, "key=titel\nfame=straße").then((resource) => { | ||
const setStringSpy = sinon.spy(resource, "setString"); | ||
const middleware = serveResourcesMiddleware({ | ||
resources: { | ||
all: readerWriter | ||
}, | ||
tree: { | ||
resources: { | ||
configuration: { | ||
propertiesFileSourceEncoding: "UTF-8" | ||
} | ||
} | ||
} | ||
}); | ||
|
||
const response = fakeResponse; | ||
|
||
const setHeaderSpy = sinon.spy(response, "setHeader"); | ||
const req = { | ||
url: "/myFile3.properties", | ||
headers: {} | ||
}; | ||
const next = function(err) { | ||
throw new Error(`Next callback called with error: ${err.message}`); | ||
}; | ||
return middleware(req, response, next).then((o) => { | ||
return resource.getString(); | ||
}).then((content) => { | ||
t.is(content, `key=titel | ||
fame=stra\\ufffde`); | ||
t.is(setHeaderSpy.callCount, 2); | ||
t.is(setStringSpy.callCount, 1); | ||
t.is(setHeaderSpy.getCall(0).lastArg, "application/octet-stream"); | ||
}); | ||
}); | ||
}); | ||
|
||
test.serial("Check if properties file is served properly without property setting", (t) => { | ||
t.plan(4); | ||
|
||
const readerWriter = resourceFactory.createAdapter({virBasePath: "/"}); | ||
|
||
return writeResource(readerWriter, "/myFile3.properties", 1024 * 1024, "key=titel\nfame=straße").then((resource) => { | ||
const setStringSpy = sinon.spy(resource, "setString"); | ||
const middleware = serveResourcesMiddleware({ | ||
resources: { | ||
all: readerWriter | ||
} | ||
}); | ||
|
||
const response = fakeResponse; | ||
|
||
const setHeaderSpy = sinon.spy(response, "setHeader"); | ||
const req = { | ||
url: "/myFile3.properties", | ||
headers: {} | ||
}; | ||
const next = function(err) { | ||
throw new Error(`Next callback called with error: ${err.stack}`); | ||
}; | ||
return middleware(req, response, next).then((o) => { | ||
return resource.getString(); | ||
}).then((content) => { | ||
t.is(content, `key=titel | ||
fame=stra\\u00dfe`); | ||
t.is(setHeaderSpy.callCount, 2); | ||
t.is(setStringSpy.callCount, 1); | ||
t.is(setHeaderSpy.getCall(0).lastArg, "application/octet-stream"); | ||
}); | ||
}); | ||
}); |
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 missed something here 🤔
project
is the root project. However, resources are taken fromresources.all
. So we rather need to look for the project on the resource. Just like we do in the lbt BundlerWe also need to add a test for this: A dependency tree of two projects, one with UTF-8 encoding and another one with ISO-8859-1, making sure that both are being processed correctly (stubs should be sufficient, no actual comparison of the results)
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.
Should be resolved with: #219