Skip to content

Commit

Permalink
Ensure emphasis ends with word boundary
Browse files Browse the repository at this point in the history
Added some unit tests for reported issues.
Updated simple-markdown to 0.7.3 to include security fix.

Fixes Sorunome#3
  • Loading branch information
twouters committed Jan 11, 2021
1 parent 4bfcba8 commit 4e6a1d7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const rules = {
},
},
em: Object.assign({}, markdown.defaultRules.em, {
match: markdown.inlineRegex(/^\b_(\S(?:\\[\s\S]|[^\\])*?\S|\S)_(?!_)/),
match: markdown.inlineRegex(/^\b_(\S(?:\\[\s\S]|[^\\])*?\S|\S)_(?!_)\b/),
parse: (capture, parse) => {
return {
content: parse(capture[1]),
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"dependencies": {
"escape-html": "^1.0.3",
"node-emoji": "^1.10.0",
"simple-markdown": "^0.7.2"
"simple-markdown": "^0.7.3"
},
"devDependencies": {
"eslint": "^6.8.0",
Expand Down
7 changes: 6 additions & 1 deletion test/single.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ test("Should convert *text* to <strong>text</strong>", () => {
.toBe("This is a <strong>test</strong> with <strong>some bold</strong> text in it");
});

it("Should convert _text_ to <em>text</dem>", () => {
it("Should convert _text_ to <em>text</em>", () => {
expect(markdown.toHTML("This is a _test_ with _some italicized_ text in it"))
.toBe("This is a <em>test</em> with <em>some italicized</em> text in it");
});

it("Should not convert inner_underscored_text to inner<em>underscored</em>text", () => {
expect(markdown.toHTML("This is a _test_ with some_italicized_text in it"))
.toBe("This is a <em>test</em> with some_italicized_text in it");
});

it("Should convert `text` to <code>text</code>", () => {
expect(markdown.toHTML("Code: `1 + 1 = 2`"))
.toBe("Code: <code>1 + 1 = 2</code>");
Expand Down
5 changes: 5 additions & 0 deletions test/slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,8 @@ it("Should disable the extra span tags, if set", () => {
expect(markdown.toHTML("hey <@ID|user>!", { noExtraSpanTags: true }))
.toBe("hey @user!");
});

it("Should handle named links mixed with underscores", () => {
expect(markdown.toHTML("Hello _sup <https://example.org/has_too|example in_ description>"))
.toBe("Hello _sup <a href=\"https://example.org/has_too\">example in_ description</a>");
});

0 comments on commit 4e6a1d7

Please sign in to comment.