Repository: remarkablemark/html-dom-parser (js)

Issue:
Carriage return replacement breaking LaTeX
## Expected Behavior

In a text document use of an escaped backslash before an `r` character should not remove the `r` character. This is necessary for e.g., LaTeX, where commands like `\right`) are common.

See https://github.com/remarkablemark/html-react-parser/issues/1634

## Actual Behavior

All `\r` are removed from the HTML string, even if the raw string is formatted as `\\r`.

Caused by #902

## Steps to Reproduce

```js
parse('<span class="math">\\left(\\right)\\rD\\rightarrow\\reals\\ni</span>');
```

## Reproducible Demo

https://stackblitz.com/edit/html-react-parser-typescript-w9j4u9vu?file=src%2Findex.tsx

## Environment

- Version: [5.0.11](https://github.com/remarkablemark/html-dom-parser/releases/tag/v5.0.11)
- Platform:
- Browser:
- OS:

## Keywords

LaTeX, carriage return, escape, unescape, special character

Pull request:
fix(client): don't break LaTeX when replacing carriage returns
## What is the motivation for this pull request?

fix(client): don't break LaTeX when replacing carriage returns

Fixes #917

Related to https://github.com/remarkablemark/html-react-parser/issues/1634

## What is the current behavior?

All `\r` are removed from the HTML string, even if the raw string is formatted as `\\r`.

## What is the new behavior?

`\\r` is no longer removed.

## Checklist:

- [x] [Conventional Commits](https://www.conventionalcommits.org/)
- [x] Tests
- [ ] [Types](https://arethetypeswrong.github.io/)
- [ ] Documentation

Patch:
diff --git a/package-lock.json b/package-lock.json
index ce428cf..1961845 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,7 +13,7 @@
         "htmlparser2": "9.1.0"
       },
       "devDependencies": {
-        "@commitlint/cli": "19.6.1",
+        "@commitlint/cli": "19.6.0",
         "@commitlint/config-conventional": "19.6.0",
         "@eslint/compat": "1.2.4",
         "@eslint/eslintrc": "3.2.0",
@@ -347,14 +347,15 @@
       }
     },
     "node_modules/@commitlint/cli": {
-      "version": "19.6.1",
-      "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.6.1.tgz",
-      "integrity": "sha512-8hcyA6ZoHwWXC76BoC8qVOSr8xHy00LZhZpauiD0iO0VYbVhMnED0da85lTfIULxl7Lj4c6vZgF0Wu/ed1+jlQ==",
+      "version": "19.6.0",
+      "resolved": "https://registry.npmjs.org/@commitlint/cli/-/cli-19.6.0.tgz",
+      "integrity": "sha512-v17BgGD9w5KnthaKxXnEg6KLq6DYiAxyiN44TpiRtqyW8NSq+Kx99mkEG8Qo6uu6cI5eMzMojW2muJxjmPnF8w==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "@commitlint/format": "^19.5.0",
         "@commitlint/lint": "^19.6.0",
-        "@commitlint/load": "^19.6.1",
+        "@commitlint/load": "^19.5.0",
         "@commitlint/read": "^19.5.0",
         "@commitlint/types": "^19.5.0",
         "tinyexec": "^0.3.0",
@@ -386,6 +387,7 @@
       "resolved": "https://registry.npmjs.org/@commitlint/config-validator/-/config-validator-19.5.0.tgz",
       "integrity": "sha512-CHtj92H5rdhKt17RmgALhfQt95VayrUo2tSqY9g2w+laAXyk7K/Ef6uPm9tn5qSIwSmrLjKaXK9eiNuxmQrDBw==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "@commitlint/types": "^19.5.0",
         "ajv": "^8.11.0"
@@ -417,6 +419,7 @@
       "resolved": "https://registry.npmjs.org/@commitlint/execute-rule/-/execute-rule-19.5.0.tgz",
       "integrity": "sha512-aqyGgytXhl2ejlk+/rfgtwpPexYyri4t8/n4ku6rRJoRhGZpLFMqrZ+YaubeGysCP6oz4mMA34YSTaSOKEeNrg==",
       "dev": true,
+      "license": "MIT",
       "engines": {
         "node": ">=v18"
       }
@@ -466,10 +469,11 @@
       }
     },
     "node_modules/@commitlint/load": {
-      "version": "19.6.1",
-      "resolved": "https://registry.npmjs.org/@commitlint/load/-/load-19.6.1.tgz",
-      "integrity": "sha512-kE4mRKWWNju2QpsCWt428XBvUH55OET2N4QKQ0bF85qS/XbsRGG1MiTByDNlEVpEPceMkDr46LNH95DtRwcsfA==",
+      "version": "19.5.0",
+      "resolved": "https://registry.npmjs.org/@commitlint/load/-/load-19.5.0.tgz",
+      "integrity": "sha512-INOUhkL/qaKqwcTUvCE8iIUf5XHsEPCLY9looJ/ipzi7jtGhgmtH7OOFiNvwYgH7mA8osUWOUDV8t4E2HAi4xA==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "@commitlint/config-validator": "^19.5.0",
         "@commitlint/execute-rule": "^19.5.0",
@@ -477,7 +481,7 @@
         "@commitlint/types": "^19.5.0",
         "chalk": "^5.3.0",
         "cosmiconfig": "^9.0.0",
-        "cosmiconfig-typescript-loader": "^6.1.0",
+        "cosmiconfig-typescript-loader": "^5.0.0",
         "lodash.isplainobject": "^4.0.6",
         "lodash.merge": "^4.6.2",
         "lodash.uniq": "^4.5.0"
@@ -533,6 +537,7 @@
       "resolved": "https://registry.npmjs.org/@commitlint/resolve-extends/-/resolve-extends-19.5.0.tgz",
       "integrity": "sha512-CU/GscZhCUsJwcKTJS9Ndh3AKGZTNFIOoQB2n8CmFnizE0VnEuJoum+COW+C1lNABEeqk6ssfc1Kkalm4bDklA==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "@commitlint/config-validator": "^19.5.0",
         "@commitlint/types": "^19.5.0",
@@ -2336,6 +2341,7 @@
       "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz",
       "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "fast-deep-equal": "^3.1.3",
         "fast-uri": "^3.0.1",
@@ -3480,6 +3486,7 @@
       "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-9.0.0.tgz",
       "integrity": "sha512-itvL5h8RETACmOTFc4UfIyB2RfEHi71Ax6E/PivVxq9NseKbOWpeyHEOIbmAw1rs8Ak0VursQNww7lf7YtUwzg==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "env-paths": "^2.2.1",
         "import-fresh": "^3.3.0",
@@ -3502,20 +3509,21 @@
       }
     },
     "node_modules/cosmiconfig-typescript-loader": {
-      "version": "6.1.0",
-      "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-6.1.0.tgz",
-      "integrity": "sha512-tJ1w35ZRUiM5FeTzT7DtYWAFFv37ZLqSRkGi2oeCK1gPhvaWjkAtfXvLmvE1pRfxxp9aQo6ba/Pvg1dKj05D4g==",
+      "version": "5.1.0",
+      "resolved": "https://registry.npmjs.org/cosmiconfig-typescript-loader/-/cosmiconfig-typescript-loader-5.1.0.tgz",
+      "integrity": "sha512-7PtBB+6FdsOvZyJtlF3hEPpACq7RQX6BVGsgC7/lfVXnKMvNCu/XY3ykreqG5w/rBNdu2z8LCIKoF3kpHHdHlA==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
-        "jiti": "^2.4.1"
+        "jiti": "^1.21.6"
       },
       "engines": {
-        "node": ">=v18"
+        "node": ">=v16"
       },
       "peerDependencies": {
         "@types/node": "*",
-        "cosmiconfig": ">=9",
-        "typescript": ">=5"
+        "cosmiconfig": ">=8.2",
+        "typescript": ">=4"
       }
     },
     "node_modules/create-require": {
@@ -4111,6 +4119,7 @@
       "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz",
       "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==",
       "dev": true,
+      "license": "MIT",
       "engines": {
         "node": ">=6"
       }
@@ -5019,7 +5028,8 @@
       "version": "3.0.3",
       "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.3.tgz",
       "integrity": "sha512-aLrHthzCjH5He4Z2H9YZ+v6Ujb9ocRuW6ZzkJQOrTxleEijANq4v1TsaPaVG1PZcuurEzrLcWRyYBYXD5cEiaw==",
-      "dev": true
+      "dev": true,
+      "license": "BSD-3-Clause"
     },
     "node_modules/fastq": {
       "version": "1.17.1",
@@ -5578,6 +5588,7 @@
       "resolved": "https://registry.npmjs.org/global-directory/-/global-directory-4.0.1.tgz",
       "integrity": "sha512-wHTUcDUoZ1H5/0iVqEudYW4/kAlN5cZ3j/bXn0Dpbizl9iaUVeWSHqiOjsgk6OW2bkLclbBjzewBz6weQ1zA2Q==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "ini": "4.1.1"
       },
@@ -6078,6 +6089,7 @@
       "resolved": "https://registry.npmjs.org/import-meta-resolve/-/import-meta-resolve-4.1.0.tgz",
       "integrity": "sha512-I6fiaX09Xivtk+THaMfAwnA3MVA5Big1WHF1Dfx9hFuvNIWpXnorlkzhcQf6ehrqQiiZECRt1poOAkPmer3ruw==",
       "dev": true,
+      "license": "MIT",
       "funding": {
         "type": "github",
         "url": "https://github.com/sponsors/wooorm"
@@ -6127,6 +6139,7 @@
       "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.1.tgz",
       "integrity": "sha512-QQnnxNyfvmHFIsj7gkPcYymR8Jdw/o7mp5ZFihxn6h8Ci6fh3Dx4E1gPjpQEpIuPo9XVNY/ZUwh4BPMjGyL01g==",
       "dev": true,
+      "license": "ISC",
       "engines": {
         "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
       }
@@ -6860,12 +6873,13 @@
       }
     },
     "node_modules/jiti": {
-      "version": "2.4.1",
-      "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.4.1.tgz",
-      "integrity": "sha512-yPBThwecp1wS9DmoA4x4KR2h3QoslacnDR8ypuFM962kI4/456Iy1oHx2RAgh4jfZNdn0bctsdadceiBUgpU1g==",
+      "version": "1.21.6",
+      "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.6.tgz",
+      "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==",
       "dev": true,
+      "license": "MIT",
       "bin": {
-        "jiti": "lib/jiti-cli.mjs"
+        "jiti": "bin/jiti.js"
       }
     },
     "node_modules/js-tokens": {
@@ -6989,7 +7003,8 @@
       "version": "1.0.0",
       "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
       "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
-      "dev": true
+      "dev": true,
+      "license": "MIT"
     },
     "node_modules/json-stable-stringify-without-jsonify": {
       "version": "1.0.1",
@@ -7408,7 +7423,8 @@
       "version": "1.2.4",
       "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz",
       "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==",
-      "dev": true
+      "dev": true,
+      "license": "MIT"
     },
     "node_modules/lint-staged": {
       "version": "15.2.11",
@@ -7570,7 +7586,8 @@
       "version": "4.0.6",
       "resolved": "https://registry.npmjs.org/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz",
       "integrity": "sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==",
-      "dev": true
+      "dev": true,
+      "license": "MIT"
     },
     "node_modules/lodash.kebabcase": {
       "version": "4.1.1",
@@ -7590,7 +7607,8 @@
       "version": "4.6.2",
       "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz",
       "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==",
-      "dev": true
+      "dev": true,
+      "license": "MIT"
     },
     "node_modules/lodash.snakecase": {
       "version": "4.1.1",
@@ -7610,7 +7628,8 @@
       "version": "4.5.0",
       "resolved": "https://registry.npmjs.org/lodash.uniq/-/lodash.uniq-4.5.0.tgz",
       "integrity": "sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==",
-      "dev": true
+      "dev": true,
+      "license": "MIT"
     },
     "node_modules/lodash.upperfirst": {
       "version": "4.3.1",
@@ -9296,6 +9315,7 @@
       "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz",
       "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==",
       "dev": true,
+      "license": "MIT",
       "dependencies": {
         "@babel/code-frame": "^7.0.0",
         "error-ex": "^1.3.1",
@@ -10074,6 +10094,7 @@
       "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
       "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
       "dev": true,
+      "license": "MIT",
       "engines": {
         "node": ">=0.10.0"
       }
@@ -10552,6 +10573,16 @@
         "url": "https://paulmillr.com/funding/"
       }
     },
+    "node_modules/size-limit/node_modules/jiti": {
+      "version": "2.4.1",
+      "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.4.1.tgz",
+      "integrity": "sha512-yPBThwecp1wS9DmoA4x4KR2h3QoslacnDR8ypuFM962kI4/456Iy1oHx2RAgh4jfZNdn0bctsdadceiBUgpU1g==",
+      "dev": true,
+      "license": "MIT",
+      "bin": {
+        "jiti": "lib/jiti-cli.mjs"
+      }
+    },
     "node_modules/size-limit/node_modules/readdirp": {
       "version": "4.0.2",
       "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-4.0.2.tgz",
diff --git a/package.json b/package.json
index 614c6fe..ee2d0d9 100644
--- a/package.json
+++ b/package.json
@@ -59,7 +59,7 @@
     "htmlparser2": "9.1.0"
   },
   "devDependencies": {
-    "@commitlint/cli": "19.6.1",
+    "@commitlint/cli": "19.6.0",
     "@commitlint/config-conventional": "19.6.0",
     "@eslint/compat": "1.2.4",
     "@eslint/eslintrc": "3.2.0",
diff --git a/src/client/constants.ts b/src/client/constants.ts
index b073d45..da5809a 100644
--- a/src/client/constants.ts
+++ b/src/client/constants.ts
@@ -44,3 +44,11 @@ export const CASE_SENSITIVE_TAG_NAMES_MAP = CASE_SENSITIVE_TAG_NAMES.reduce(
   },
   {} as Record<string, string>,
 );
+
+export const CARRIAGE_RETURN = '\r';
+export const CARRIAGE_RETURN_REGEX = new RegExp(CARRIAGE_RETURN, 'g');
+export const CARRIAGE_RETURN_PLACEHOLDER = `__HTML_DOM_PARSER_CARRIAGE_RETURN_PLACEHOLDER_${Date.now()}__`;
+export const CARRIAGE_RETURN_PLACEHOLDER_REGEX = new RegExp(
+  CARRIAGE_RETURN_PLACEHOLDER,
+  'g',
+);
diff --git a/src/client/utilities.ts b/src/client/utilities.ts
index 05ed18c..7b51b7b 100644
--- a/src/client/utilities.ts
+++ b/src/client/utilities.ts
@@ -1,7 +1,13 @@
 import { Comment, Element, ProcessingInstruction, Text } from 'domhandler';
 
 import type { DOMNode } from '../types';
-import { CASE_SENSITIVE_TAG_NAMES_MAP } from './constants';
+import {
+  CARRIAGE_RETURN,
+  CARRIAGE_RETURN_PLACEHOLDER,
+  CARRIAGE_RETURN_PLACEHOLDER_REGEX,
+  CARRIAGE_RETURN_REGEX,
+  CASE_SENSITIVE_TAG_NAMES_MAP,
+} from './constants';
 
 /**
  * Gets case-sensitive tag name.
@@ -58,7 +64,7 @@ function formatTagName(tagName: string): string {
  * @returns - HTML string with escaped special characters.
  */
 export function escapeSpecialCharacters(html: string): string {
-  return html.replace(/\r/g, '\\r');
+  return html.replace(CARRIAGE_RETURN_REGEX, CARRIAGE_RETURN_PLACEHOLDER);
 }
 
 /**
@@ -68,7 +74,7 @@ export function escapeSpecialCharacters(html: string): string {
  * @returns - Text with escaped characters reverted.
  */
 export function revertEscapedCharacters(text: string): string {
-  return text.replace(/\\r/g, '\r');
+  return text.replace(CARRIAGE_RETURN_PLACEHOLDER_REGEX, CARRIAGE_RETURN);
 }
 
 /**


Test patch:
diff --git a/test/cases/html.js b/test/cases/html.js
index e946331..2b924ac 100644
--- a/test/cases/html.js
+++ b/test/cases/html.js
@@ -327,6 +327,16 @@ module.exports = [
     data: '<div>Hello\r<span>Beautiful\r</span>World</div>',
   },
 
+  // LaTeX
+  {
+    name: 'LaTeX',
+    data: '<span class="math">\\left(\\right)\\rD\\rightarrow\\reals\\ni</span>',
+  },
+  {
+    name: 'LaTeX with carriage return',
+    data: '<span class="math">\\left(\\right)\\rD\\rightarrow\\reals\\ni</span>\r\n',
+  },
+
   // custom tag
   {
     name: 'custom tag',
diff --git a/test/cases/index.js b/test/cases/index.js
index 029d9b5..916b88d 100644
--- a/test/cases/index.js
+++ b/test/cases/index.js
@@ -34,3 +34,5 @@ module.exports = {
   html,
   svg,
 };
+
+module.exports.default = module.exports;
diff --git a/test/server/client.test.ts b/test/server/client.test.ts
index 8bc5a1f..097b22f 100644
--- a/test/server/client.test.ts
+++ b/test/server/client.test.ts
@@ -1,5 +1,6 @@
 import { expect } from 'chai';
 
+import { CARRIAGE_RETURN_PLACEHOLDER } from '../../src/client/constants';
 import { formatDOM } from '../../src/client/utilities';
 import { revertEscapedCharacters } from '../../src/client/utilities';
 import { escapeSpecialCharacters } from '../../src/client/utilities';
@@ -15,59 +16,67 @@ describe('client utilities', () => {
 
   describe('escapeSpecialCharacters', () => {
     it('escapes carriage return characters', () => {
-      const input = 'Hello\rWorld';
-      const expected = 'Hello\\rWorld';
-      expect(escapeSpecialCharacters(input)).to.equal(expected);
+      expect(escapeSpecialCharacters('Hello\rWorld')).to.equal(
+        `Hello${CARRIAGE_RETURN_PLACEHOLDER}World`,
+      );
     });
 
     it('does not modify strings without special characters', () => {
-      const input = 'Hello World';
-      expect(escapeSpecialCharacters(input)).to.equal(input);
+      const text = 'Hello World';
+      expect(escapeSpecialCharacters(text)).to.equal(text);
     });
 
     it('handles empty strings', () => {
-      expect(escapeSpecialCharacters('')).to.equal('');
+      const text = '';
+      expect(escapeSpecialCharacters(text)).to.equal(text);
     });
 
     it('handles multiple carriage returns', () => {
-      const input = 'Hello\rDear\rWorld';
-      const expected = 'Hello\\rDear\\rWorld';
-      expect(escapeSpecialCharacters(input)).to.equal(expected);
+      expect(escapeSpecialCharacters('Hello\rDear\rWorld')).to.equal(
+        `Hello${CARRIAGE_RETURN_PLACEHOLDER}Dear${CARRIAGE_RETURN_PLACEHOLDER}World`,
+      );
     });
 
     it('only escapes carriage returns', () => {
-      const input = 'Hello\rWorld\n'; // \n should not be affected
-      const expected = 'Hello\\rWorld\n';
-      expect(escapeSpecialCharacters(input)).to.equal(expected);
+      // `\n` and `\right` should not be affected
+      expect(escapeSpecialCharacters('Hello\rWorld\n\right')).to.equal(
+        `Hello${CARRIAGE_RETURN_PLACEHOLDER}World\n${CARRIAGE_RETURN_PLACEHOLDER}ight`,
+      );
     });
   });
 
   describe('revertEscapedCharacters', () => {
     it('reverts escaped carriage return characters', () => {
-      const input = 'Hello\\rWorld';
-      const expected = 'Hello\rWorld';
-      expect(revertEscapedCharacters(input)).to.equal(expected);
+      expect(
+        revertEscapedCharacters(`Hello${CARRIAGE_RETURN_PLACEHOLDER}World`),
+      ).to.equal('Hello\rWorld');
     });
 
     it('does not modify strings without escaped characters', () => {
-      const input = 'Hello World';
-      expect(revertEscapedCharacters(input)).to.equal(input);
+      const text = 'Hello World';
+      expect(revertEscapedCharacters(text)).to.equal(text);
     });
 
     it('handles empty strings', () => {
-      expect(revertEscapedCharacters('')).to.equal('');
+      const text = '';
+      expect(revertEscapedCharacters(text)).to.equal(text);
     });
 
     it('handles multiple escaped carriage returns', () => {
-      const input = 'Hello\\rDear\\rWorld';
-      const expected = 'Hello\rDear\rWorld';
-      expect(revertEscapedCharacters(input)).to.equal(expected);
+      expect(
+        revertEscapedCharacters(
+          `Hello${CARRIAGE_RETURN_PLACEHOLDER}Dear${CARRIAGE_RETURN_PLACEHOLDER}World`,
+        ),
+      ).to.equal('Hello\rDear\rWorld');
     });
 
     it('only reverts escaped carriage returns', () => {
-      const input = 'Hello\\rWorld\\n'; // \n should not be affected
-      const expected = 'Hello\rWorld\\n';
-      expect(revertEscapedCharacters(input)).to.equal(expected);
+      // `\n` and `\right` should not be affected
+      expect(
+        revertEscapedCharacters(
+          `Hello${CARRIAGE_RETURN_PLACEHOLDER}World\\n\\right`,
+        ),
+      ).to.equal('Hello\rWorld\\n\\right');
     });
   });
 });