@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.js CHANGED
@@ -360,8 +360,14 @@ var KNOWN_VR_CODES = /* @__PURE__ */ new Set([
360
360
  "UT",
361
361
  "UV"
362
362
  ]);
363
+ function decodeXmlEntities(value) {
364
+ return value.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&quot;/g, '"').replace(/&apos;/g, "'").replace(/&amp;/g, "&");
365
+ }
366
+ function decodeIfString(value) {
367
+ return typeof value === "string" ? decodeXmlEntities(value) : value;
368
+ }
363
369
  function buildPnString(comp) {
364
- const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""];
370
+ const parts = [comp.FamilyName ?? "", comp.GivenName ?? "", comp.MiddleName ?? "", comp.NamePrefix ?? "", comp.NameSuffix ?? ""].map(decodeXmlEntities);
365
371
  let last = parts.length - 1;
366
372
  for (; last >= 0; last--) {
367
373
  if (parts[last] !== "") break;
@@ -400,9 +406,9 @@ function convertBulkDataURI(attr, element) {
400
406
  const bulkArray = toArray(attr.BulkDataURI);
401
407
  const firstBulk = bulkArray[0];
402
408
  if (typeof firstBulk === "object" && firstBulk !== null && "@_uri" in firstBulk) {
403
- element.BulkDataURI = safeString(firstBulk["@_uri"]);
409
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk["@_uri"]));
404
410
  } else {
405
- element.BulkDataURI = safeString(firstBulk);
411
+ element.BulkDataURI = decodeXmlEntities(safeString(firstBulk));
406
412
  }
407
413
  }
408
414
  function convertPNValue(attr, element) {
@@ -446,7 +452,7 @@ function convertRegularValue(attr, element, vr) {
446
452
  const values = [];
447
453
  const isNumeric = NUMERIC_JSON_VRS.has(vr);
448
454
  for (const v of valArray) {
449
- const unwrapped = unwrapValue(v);
455
+ const unwrapped = decodeIfString(unwrapValue(v));
450
456
  values.push(isNumeric ? coerceNumeric(unwrapped) : unwrapped);
451
457
  }
452
458
  if (values.length > 0) element.Value = values;