Skip to content

Commit

Permalink
Take care on non-standard Microsoft XMP tag Rating
Browse files Browse the repository at this point in the history
Rename it to RatingPercent just like e.g. exiftool does.

Resolves: #148
  • Loading branch information
mattiasw committed Apr 25, 2021
1 parent 1f6f96d commit 2e5a4a4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dist/exif-reader.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/exif-reader.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/xmp-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ function isNamespaceDefinition(name) {
}

function getLocalName(name) {
if (/^MicrosoftPhoto(_\d+_)?:Rating$/i.test(name)) {
return 'RatingPercent';
}
return name.split(':')[1];
}

Expand Down
2 changes: 2 additions & 0 deletions test/build/update.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Add/update a single file:
// npm run test:build:update -- --image=<filename without path>
const path = require('path');
const fs = require('fs');
const {execSync} = require('child_process');
Expand Down
26 changes: 26 additions & 0 deletions test/unit/xmp-tags-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,32 @@ describe('xmp-tags', () => {
}
});
});

describe('exceptions', () => {
it('should rename MicrosoftPhoto:Rating to RatingPercent', () => {
const xmlString = getXmlString(`
<rdf:Description xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
<xmp:Rating>3</xmp:Rating>
<MicrosoftPhoto:Rating>50</MicrosoftPhoto:Rating>
<MicroSoftPhoto_1_:Rating>50</MicroSoftPhoto_1_:Rating>
</rdf:Description>
`);
const dataView = getDataView(xmlString);
const tags = XmpTags.read(dataView, [{dataOffset: 0, length: xmlString.length}]);
expect(tags).to.deep.equal({
Rating: {
value: '3',
attributes: {},
description: '3'
},
RatingPercent: {
value: '50',
attributes: {},
description: '50'
}
});
});
});
});

function getXmlStringWithPacketWrapper(content) {
Expand Down

0 comments on commit 2e5a4a4

Please sign in to comment.