Skip to content

Commit

Permalink
Merge pull request #746 from tomekzaw/@tomekzaw/rename-escape-unescape
Browse files Browse the repository at this point in the history
Rename `escape`/`unescape` to `escapeText`/`unescapeText`
  • Loading branch information
roryabraham authored Jul 16, 2024
2 parents f1e8956 + 293c238 commit 53cad96
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __tests__/ExpensiMark-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test('Test with regex Maximum regex stack depth reached error', () => {
throw new Error('Maximum regex stack depth reached');
});
expensiMarkParser.modifyTextForUrlLinks = modifyTextForUrlLinksMock;
expect(expensiMarkParser.replace(testString)).toBe(Utils.escape(testString));
expect(expensiMarkParser.replace(testString)).toBe(Utils.escapeText(testString));
expect(modifyTextForUrlLinksMock).toHaveBeenCalledTimes(1);

// Mock method extractLinksInMarkdownComment to let it return undefined to test try/catch of method ExpensiMark.extractLinksInMarkdownComment
Expand Down
6 changes: 3 additions & 3 deletions lib/ExpensiMark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ export default class ExpensiMark {
*/
replace(text: string, {filterRules = [], shouldEscapeText = true, shouldKeepRawInput = false, disabledRules = [], extras = EXTRAS_DEFAULT}: ReplaceOptions = {}): string {
// This ensures that any html the user puts into the comment field shows as raw html
let replacedText = shouldEscapeText ? Utils.escape(text) : text;
let replacedText = shouldEscapeText ? Utils.escapeText(text) : text;
const rules = this.getHtmlRuleset(filterRules, disabledRules, shouldKeepRawInput);

const processRule = (rule: Rule) => {
Expand All @@ -877,7 +877,7 @@ export default class ExpensiMark {
ExpensiMark.Log.alert('Error replacing text with html in ExpensiMark.replace', {error: e});

// We want to return text without applying rules if exception occurs during replacing
return shouldEscapeText ? Utils.escape(text) : text;
return shouldEscapeText ? Utils.escapeText(text) : text;
}

return replacedText;
Expand Down Expand Up @@ -1273,7 +1273,7 @@ export default class ExpensiMark {
// When the attribute contains HTML and is converted back to MD we need to re-escape it to avoid
// illegal attribute value characters like `," or ' which might break the HTML
originalContent = Str.replaceAll(originalContent, '\n', '');
return Utils.escape(originalContent);
return Utils.escapeText(originalContent);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/components/form/element/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ class Combobox extends React.Component {
aria-label="..."
onChange={this.performSearch}
onKeyDown={this.closeDropdownOnTabOut}
value={this.props.propertyToDisplay === 'value' ? Utils.unescape(this.state.currentValue) : Utils.unescape(this.state.currentText.replace(/ /g, ''))}
value={this.props.propertyToDisplay === 'value' ? Utils.unescapeText(this.state.currentValue) : Utils.unescapeText(this.state.currentText.replace(/ /g, ''))}
onFocus={this.openDropdown}
autoComplete="off"
placeholder={this.props.placeholder}
Expand Down
2 changes: 1 addition & 1 deletion lib/str.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const Str = {
* @returns The escaped string
*/
safeEscape(s: string) {
return Utils.escape(Utils.unescape(s));
return Utils.escapeText(Utils.unescapeText(s));
},

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
* corresponding HTML entities.
* Source: https://github.com/lodash/lodash/blob/main/src/escape.ts
*/
function escape(string: string): string {
function escapeText(string: string): string {
return string && reHasUnescapedHtml.test(string) ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr as keyof typeof htmlEscapes]) : string || '';
}

Expand All @@ -47,7 +47,7 @@ const reHasEscapedHtml = RegExp(reEscapedHtml.source);
* their corresponding characters.
* Source: https://github.com/lodash/lodash/blob/main/src/unescape.ts
* */
function unescape(string: string): string {
function unescapeText(string: string): string {
return string && reHasEscapedHtml.test(string) ? string.replace(reEscapedHtml, (entity) => htmlUnescapes[entity as keyof typeof htmlUnescapes] || "'") : string || '';
}

Expand All @@ -70,4 +70,4 @@ function isObject(obj: unknown): boolean {
return type === 'function' || (!!obj && type === 'object');
}

export {isWindowAvailable, isNavigatorAvailable, escape, unescape, isFunction, isObject};
export {isWindowAvailable, isNavigatorAvailable, escapeText, unescapeText, isFunction, isObject};

0 comments on commit 53cad96

Please sign in to comment.