Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename escape/unescape to escapeText/unescapeText #746

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -812,7 +812,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 @@ -838,7 +838,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 @@ -1230,7 +1230,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};
Loading