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

fix escaping of title when generating a markdown link #2456

Merged
merged 1 commit into from
Feb 7, 2020
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
15 changes: 15 additions & 0 deletions CliClient/tests/markdownUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ describe('markdownUtils', function() {
}
}));

it('escape a markdown link (title)', asyncTest(async () => {

const testCases = [
['Helmut K. C. Tessarek', 'Helmut K. C. Tessarek'],
['Helmut (K. C.) Tessarek', 'Helmut (K. C.) Tessarek'],
['Helmut [K. C.] Tessarek', 'Helmut \\[K. C.\\] Tessarek'],
];

for (let i = 0; i < testCases.length; i++) {
const md = testCases[i][0];
const expected = testCases[i][1];
expect(markdownUtils.escapeTitleText(md)).toBe(expected);
}
}));

});
5 changes: 5 additions & 0 deletions ReactNativeClient/lib/markdownUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ const markdownUtils = {
return text.replace(/(\[|\]|\(|\))/g, '_');
},

// Titles for markdown links only need escaping for [ and ]
escapeTitleText(text) {
return text.replace(/(\[|\])/g, '\\$1');
},

escapeLinkUrl(url) {
url = url.replace(/\(/g, '%28');
url = url.replace(/\)/g, '%29');
Expand Down
2 changes: 1 addition & 1 deletion ReactNativeClient/lib/models/BaseItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class BaseItem extends BaseModel {

const output = [];
output.push('[');
output.push(markdownUtils.escapeLinkText(item.title));
output.push(markdownUtils.escapeTitleText(item.title));
output.push(']');
output.push(`(:/${item.id})`);
return output.join('');
Expand Down