exifreader 4.39.0 → 4.39.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "exifreader",
3
- "version": "4.39.0",
3
+ "version": "4.39.1",
4
4
  "description": "Library that parses Exif metadata in images.",
5
5
  "author": "Mattias Wallander <mattias@wallander.eu>",
6
6
  "repository": {
@@ -6,6 +6,23 @@ import TextDecoder from './text-decoder.js';
6
6
 
7
7
  const TAG_HEADER_SIZE = 5;
8
8
 
9
+ // Windows-1252 (CP1252) mapping for the 0x80–0x9F range, which is where it
10
+ // differs from ISO-8859-1. Bytes outside this range map identically in the
11
+ // two encodings. Five positions (0x81, 0x8D, 0x8F, 0x90, 0x9D) are unassigned
12
+ // in CP1252; we keep their raw byte value so the data is still
13
+ // representable. We do not delegate to TextDecoder('windows-1252') because
14
+ // Node.js's built-in implementation regressed in 20.18.3 / 22.13.0 / 23.4.0
15
+ // and returns the raw bytes for 0x80–0x9F instead of the WHATWG-specified
16
+ // codepoints (nodejs/node#60888, still tracked under nodejs/node#61041).
17
+ const WINDOWS_1252_C1_MAP = {
18
+ 0x80: 0x20ac, 0x82: 0x201a, 0x83: 0x0192, 0x84: 0x201e, 0x85: 0x2026,
19
+ 0x86: 0x2020, 0x87: 0x2021, 0x88: 0x02c6, 0x89: 0x2030, 0x8a: 0x0160,
20
+ 0x8b: 0x2039, 0x8c: 0x0152, 0x8e: 0x017d,
21
+ 0x91: 0x2018, 0x92: 0x2019, 0x93: 0x201c, 0x94: 0x201d, 0x95: 0x2022,
22
+ 0x96: 0x2013, 0x97: 0x2014, 0x98: 0x02dc, 0x99: 0x2122, 0x9a: 0x0161,
23
+ 0x9b: 0x203a, 0x9c: 0x0153, 0x9e: 0x017e, 0x9f: 0x0178,
24
+ };
25
+
9
26
  export default {
10
27
  decode,
11
28
  TAG_HEADER_SIZE
@@ -25,7 +42,29 @@ function decode(encoding, tagValue) {
25
42
  }
26
43
 
27
44
  const stringValue = tagValue.map((charCode) => String.fromCharCode(charCode)).join('');
28
- return decodeAsciiValue(stringValue);
45
+ try {
46
+ return decodeURIComponent(escape(stringValue));
47
+ } catch (error) {
48
+ // The bytes are not valid UTF-8. Many real-world IPTC blocks have no
49
+ // Coded Character Set tag but use Windows-1252 (en/em dashes,
50
+ // ellipsis, smart quotes, etc.). Remap the bytes through CP1252 so
51
+ // those characters render correctly instead of staying as C1 control
52
+ // characters.
53
+ return decodeWindows1252(tagValue);
54
+ }
55
+ }
56
+
57
+ function decodeWindows1252(tagValue) {
58
+ const isDataView = tagValue instanceof DataView;
59
+ const length = isDataView ? tagValue.byteLength : tagValue.length;
60
+ const getByte = isDataView ? (i) => tagValue.getUint8(i) : (i) => tagValue[i];
61
+ const codePoints = new Array(length);
62
+ for (let i = 0; i < length; i++) {
63
+ const byte = getByte(i);
64
+ const mapped = WINDOWS_1252_C1_MAP[byte];
65
+ codePoints[i] = mapped !== undefined ? mapped : byte;
66
+ }
67
+ return String.fromCharCode.apply(null, codePoints);
29
68
  }
30
69
 
31
70
  function decodeAsciiValue(asciiValue) {