Skip to content

Commit

Permalink
[FIX] ResourceTagCollection: Do not validate class of resource
Browse files Browse the repository at this point in the history
This can lead to issues where a custom task creates resources using a
different version of @ui5/fs. These reosurces will fail the instanceof
check that was implemented here.

Instead of checking for the class, we now validate that the resource has
a path. The path is currently the only relevant attribute for
ResourceTagCollection and mandatory for Resources.

Resolves https://github.com/SAP/ui5-fs/issues/269
  • Loading branch information
RandomByte committed Aug 12, 2020
1 parent a2021ac commit c52c9f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/ResourceTagCollection.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const tagNamespaceRegExp = new RegExp("^[a-z][a-z0-9]*$"); // part before the colon
const tagNameRegExp = new RegExp("^[A-Z][A-Za-z0-9]+$"); // part after the colon

const Resource = require("./Resource");

class ResourceTagCollection {
constructor({allowedTags}) {
if (!allowedTags || !allowedTags.length) {
Expand Down Expand Up @@ -47,8 +45,9 @@ class ResourceTagCollection {
}

_validateResource(resource) {
if (!(resource instanceof Resource)) {
throw new Error(`Invalid Resource: Must be instance of @ui5/fs.Resource`);
const path = resource.getPath();
if (!path) {
throw new Error(`Invalid Resource: Resource path must not be empty`);
}
}

Expand Down
14 changes: 14 additions & 0 deletions test/lib/ResourceTagCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,17 @@ test("_validateValue: Invalid value null", (t) => {
message: "Invalid Tag Value: Must be of type string, number or boolean but is object"
});
});

test("_validateResource: Empty path", (t) => {
const tagCollection = new ResourceTagCollection({
allowedTags: ["abc:MyTag"]
});
t.throws(() => {
tagCollection._validateResource({
getPath: () => ""
});
}, {
instanceOf: Error,
message: "Invalid Resource: Resource path must not be empty"
});
});

0 comments on commit c52c9f7

Please sign in to comment.