Search code examples
evalreloadscorm1.2

Unterminated string literal error while storing lesson_location


I have this error that doesnt give any indication as to what is the problem:

I'm trying to store this string in lesson_location field:

B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dKyllQxhJcNp TFBTk1iSWhBvYBhvYGAKABXXVRI&#3d;

but it throws SyntaxError: unterminated string literal

when I've modified the way the reload stores the data in ReloadAPIAdaptor.js

from using eval on entire string:

eval("this.cmi.core.lesson_location.cmivalue =\"B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dAzXnJwMozFB TU1ual4pAMimU3Q&#3d;\";");

to evaluate object first:

var o = eval("this." + element);
console.log("o",o);
if(o) o.cmivalue = value;

then it stores data without error,

now I can't modify the code in any lms so this was only to identify if the string can't be stored but it can. Just evil doesnt work so the question is what is in the given string that eval doesnt like and how to fix it.


Solution

  • There is nothing wrong with your string if you're doing the following:

    API.SetValue("cmi.core.lesson_location", "B^$eNrT0srLywNiLRANpiAsMAknoMKognlwdUi6ERrQuDARmCwmE2EMslOQ9aFaguw6dKyllQxhJcNp TFBTk1iSWhBvYBhvYGAKABXXVRI&#3d;");
    

    (where API is a reference to the window's API object)

    The string is valid as far as SCORM is concerned, and the length falls within the acceptable character limit.

    If you're encountering an issue, it might be a bug within the Reload wrapper. Frankly, the code in the Reload wrapper (as found on SourceForge) is TEN years old. It uses eval() and other JavaScript techniques that have been identified as problematic, and are highly discouraged by leading JavaScript developers. Your bug might very well be related to the wrapper's use of eval().

    I'd try using a different wrapper and see if it makes a difference.