Skip to content

Commit

Permalink
[FIX] Discovery middleware shouldn't fail when lib names overlap (#362)
Browse files Browse the repository at this point in the history
When a library's name is a prefix of another library's name (like with sap.m and sap.me), the discovery service mistakenly assigned test pages to both libraries.

By including the slash in the prefix check, only full segment matches will be taken into account.

By checking the prefixes from longest to shortest and by aborting after the first match, non-prefix-free lib names can be handled properly. The longest matching prefix will win and there won't be double assignments.
  • Loading branch information
codeworrior committed Sep 24, 2020
1 parent d9a3ce6 commit f5067ce
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/middleware/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,22 @@ function createMiddleware({resources}) {
const match = librariesPattern.exec(relPath);
if (match) {
const lib = match[1];
libs[lib] = lib.replace(/\//g, ".");
libs[lib + "/"] = lib.replace(/\//g, ".");
}
});

const libPrefixes = Object.keys(libs).sort().reverse();
testPageResources.forEach(function(resource) {
const relPath = resource.getPath().substr(16); // cut off leading "/test-resources/"
if (testPagesPattern.test(relPath)) {
Object.keys(libs).forEach(function(lib) {
if (relPath.indexOf(lib) === 0) {
libPrefixes.some(function(lib) {
if (relPath.startsWith(lib)) {
response.push({
lib: libs[lib],
name: relPath.substr(lib.length + 1),
name: relPath.substr(lib.length),
url: "../" + relPath
});
return true; // abort loop
}
});
}
Expand Down

0 comments on commit f5067ce

Please sign in to comment.