Skip to content

Commit

Permalink
fixed bug in get-attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Jul 25, 2020
1 parent 12e1d21 commit 1e9b88d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xml-utils",
"version": "0.1.0",
"version": "0.2.0",
"description": "Parse XML without Blowing Up Your Bundle Size",
"main": "src/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/get-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ function getAttribute(tag, attributeName, options) {

const xml = typeof tag === "object" ? tag.outer : tag;

const pattern = `${attributeName}\\="\(.*\)"`;
const pattern = `${attributeName}\\="\([^"]*\)"`;
if (debug) console.log("pattern:", pattern);

const re = new RegExp(pattern);
const match = re.exec(xml);
if (debug) console.log("match:", match);
if (match) return match[1];
}

Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,10 @@ describe('getAttribute', function() {
const key = getAttribute(mdi, 'key', { debug: false });
expect(key).to.equal('SourceBandIndex');
});
it("should get raster width from a .mrf file", function() {
const rasterSize = '<Size x="6638" y="7587" c="4" />';
expect(getAttribute(rasterSize, 'x')).to.equal("6638");
expect(getAttribute(rasterSize, 'y')).to.equal("7587");
expect(getAttribute(rasterSize, 'c')).to.equal("4");
});
});

0 comments on commit 1e9b88d

Please sign in to comment.