This project is read-only.
1
Vote

encodeValue() function distort the string data with braces

description

var encodeValue = function (value) {
    // Handle GUIDs wrapped in braces
    if (typeof value == typeof "" && value.slice(0, 1) === "{" && value.slice(-1) === "}") {
        value = value.slice(1, -1);
    }

    // ReSharper disable QualifiedExpressionMaybeNull
    return (typeof value === "object" && value.getTime)
    // ReSharper restore QualifiedExpressionMaybeNull
           ? encodeDate(value)
           : crmXmlEncode(value);
};
Ex: If I try to update an object using XrmServiceToolkit.soap.Update(EntityObj), that contains a string in braces (for example, JSON string after stringify) - external braces will be cut by encodeValue().
You should more carefully define GUID. For example, using a regular expression. In any case you should not process (destroy) user data in the query.

comments

con_ssc wrote Apr 11, 2016 at 12:41 PM

Proposal for improved handling of guids could look like this maybe?
function isGuid(guidString) {
    if( typeof guidString === "string" && guidString.test(/^\{?[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}\}?$/i)){
        return true;
    } else {
        return false;
    }
}

function encodeValue(value) {
    // Handle GUIDs wrapped in braces
    if (isGuid(value)) {
        value = value.replace(/[{}]/gi, "");
    }

    return (typeof value === "object" && value.getTime)
            ? encodeDate(value)
            : crmXmlEncode(value);
}