@patch-adams/core 1.5.8 → 1.5.9

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/index.js CHANGED
@@ -616,12 +616,30 @@ function generateLrsBridgeCode(options) {
616
616
  });
617
617
  }
618
618
 
619
- // Decode HTML entities (e.g., " " & ') to clean text
619
+ // Clean HTML entities from text \u2014 handles both proper (") and broken (quot;) forms
620
+ // Rise strips the & from entities in SCORM interaction IDs, so we need both
620
621
  function decodeEntities(str) {
621
622
  if (!str || typeof str !== 'string') return str;
622
- var txt = document.createElement('textarea');
623
- txt.innerHTML = str;
624
- return txt.value;
623
+ // 1. Replace known broken entities (without &) that Rise leaves behind
624
+ str = str
625
+ .replace(/quot;/g, '"')
626
+ .replace(/apos;/g, "'")
627
+ .replace(/amp;/g, '&')
628
+ .replace(/lt;/g, '<')
629
+ .replace(/gt;/g, '>')
630
+ .replace(/nbsp;/g, ' ');
631
+ // 2. Replace numeric entities like &#34; &#39; &#x22; etc.
632
+ str = str.replace(/&#(x?[0-9a-fA-F]+);/g, function(match, code) {
633
+ var num = code.charAt(0) === 'x' ? parseInt(code.substring(1), 16) : parseInt(code, 10);
634
+ return isNaN(num) ? match : String.fromCharCode(num);
635
+ });
636
+ // 3. Catch any remaining standard &entities; via textarea decode
637
+ try {
638
+ var txt = document.createElement('textarea');
639
+ txt.innerHTML = str;
640
+ str = txt.value;
641
+ } catch (e) {}
642
+ return str;
625
643
  }
626
644
 
627
645
  LRS.sessionId = generateUUID();