ask-sdk-core
Version:
Core package for Alexa Skills Kit SDK
39 lines • 1.61 kB
JavaScript
/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.escapeXmlCharacters = void 0;
/**
* return the string with all invalid XML characters escaped
* @param input
*/
function escapeXmlCharacters(input) {
const invalidXmlCharactersMapping = {
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": ''',
};
const invalidXmlCharactersMappingReverse = Object.keys(invalidXmlCharactersMapping).reduce(
/* eslint-disable-next-line */
(obj, key) => {
obj[invalidXmlCharactersMapping[key]] = key;
return obj;
}, {});
// sanitize any already escaped character to ensure they are not escaped more than once
const sanitizedInput = input.replace(/&|<|>|"|']/g, (c) => invalidXmlCharactersMappingReverse[c]);
return sanitizedInput.replace(/[&'"><]/g, (c) => invalidXmlCharactersMapping[c]);
}
exports.escapeXmlCharacters = escapeXmlCharacters;
//# sourceMappingURL=SsmlUtils.js.map
;