Skip to content
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] LibraryFormatter: Fix handling of paths containing special characters #622

Merged
merged 2 commits into from
Jul 1, 2021

Conversation

RandomByte
Copy link
Member

FS paths containing characters which can be interpreted as regular
expression metacharacters may lead to issues during the namespaces
detection of libraries.

Alternatively we could switch to using
https://www.npmjs.com/package/escape-string-regexp which we already use
elsewhere. But I think this case here can be kept simple.

Fixes SAP/ui5-tooling#526

@coveralls
Copy link

coveralls commented Jun 23, 2021

Coverage Status

Coverage decreased (-0.03%) to 94.693% when pulling a1a14dd on fix-library-namespace-regex-paths into 46ce7c4 on master.

const basePathPrefixRegExp = new RegExp(`^${posixBasePath}/?`);

if (!basePathPrefixRegExp.test(posixFsPath)) {
if (!posixFsPath.startsWith(posixBasePath)) {
if (posixBasePath === posixFsPath + "/") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this condition suggests to me that posixBasePath always ends with a slash, but the test mocks the method with a return value without a trailing slash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed we should ensure that posixBasePath ends with a slash to make this comparison stable

if (namespacePath.startsWith("/")) {
// Remove any leading slash
namespacePath = namespacePath.substr(1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the else case, isn't it an error? Depends on the question whether posixBasePath ends with a slash (then it's not an error) or not.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we don't enforce the presence (or absence) of a trailing slash in the project path mapping, we need to deal with both cases. I updated my initial commit to deal with optional trailing slashes everywhere and make the comparison somewhat easier to understand

…acters

FS paths containing characters which can be interpreted as regular
expression metacharacters may lead to issues during the namespace
detection of libraries.

Alternatively we could switch to using
https://www.npmjs.com/package/escape-string-regexp which we already use
elsewhere. But I think this case here can be kept simple.

Fixes SAP/ui5-tooling#526
Since we don't validate namespaces yet, they may contain regular
expression metacharacters which can lead to unexpected behaviors when
using them in a dynamically created RegExp instance.
@RandomByte RandomByte force-pushed the fix-library-namespace-regex-paths branch from 044f088 to a1a14dd Compare June 28, 2021 13:21
@RandomByte RandomByte requested a review from codeworrior June 29, 2021 11:07
@RandomByte RandomByte merged commit 4cf6bd5 into master Jul 1, 2021
@RandomByte RandomByte deleted the fix-library-namespace-regex-paths branch July 1, 2021 08:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UI5 tooling rejects paths with parentheses
4 participants