Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License 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.
*/
// @ts-ignore
import regenerate from 'regenerate';
import stripAnsi from 'strip-ansi';
// create a regular expression using regenerate() that selects any character that is explicitly allowed by https://www.w3.org/TR/xml/#NT-Char
const validXmlCharsRE = new RegExp(
`(?:${regenerate()
.add(0x9, 0xa, 0xd)
.addRange(0x20, 0xd7ff)
.addRange(0xe000, 0xfffd)
.addRange(0x10000, 0x10ffff)
.toString()})*`,
'g'
);
export function escapeCdata(input: string) {
const match = stripAnsi(input).match(validXmlCharsRE) || [];
return match.join('');
}