@ubercode/dcmtk 0.15.0 → 0.16.0

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/dist/tools.cjs CHANGED
@@ -366,8 +366,14 @@ var KNOWN_VR_CODES = /* @__PURE__ */ new Set([
366
366
  "UT",
367
367
  "UV"
368
368
  ]);
369
+ function decodeXmlEntities(value) {
370
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
371
+ }
372
+ function decodeIfString(value) {
373
+ return typeof value === "string" ? decodeXmlEntities(value) : value;
374
+ }
369
375
  function buildPnString(comp) {
370
- const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""];
376
+ const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""].map(decodeXmlEntities);
371
377
  let last = parts.length - 1;
372
378
  for (; last >= 0; last--) {
373
379
  if (parts[last] !== "") break;
@@ -406,9 +412,9 @@ function convertBulkDataURI(attr, element) {
406
412
  const bulkArray = toArray(attr.BulkDataURI);
407
413
  const firstBulk = bulkArray[0];
408
414
  if (typeof firstBulk === "object" && firstBulk !== null && "@_uri" in firstBulk) {
409
- element.BulkDataURI = safeString(firstBulk["@_uri"]);
415
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk["@_uri"]));
410
416
  } else {
411
- element.BulkDataURI = safeString(firstBulk);
417
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk));
412
418
  }
413
419
  }
414
420
  function convertPNValue(attr, element) {
@@ -452,7 +458,7 @@ function convertRegularValue(attr, element, vr) {
452
458
  const values = [];
453
459
  const isNumeric = NUMERIC_JSON_VRS.has(vr);
454
460
  for (const v of valArray) {
455
- const unwrapped = unwrapValue(v);
461
+ const unwrapped = decodeIfString(unwrapValue(v));
456
462
  values.push(isNumeric ? coerceNumeric(unwrapped) : unwrapped);
457
463
  }
458
464
  if (values.length > 0) element.Value = values;