correct more edge cases with new engine

This commit is contained in:
Sam 2017-07-17 17:25:40 -04:00
parent 8921058c67
commit c7b0764089
3 changed files with 11 additions and 12 deletions

View File

@ -64,7 +64,7 @@ export function buildEmojiUrl(code, opts) {
url = opts.customEmoji[code]; url = opts.customEmoji[code];
} }
const noToneMatch = code.match(/(.?[\w-]*)?:?/); const noToneMatch = code.match(/([^:]+):?/);
if (noToneMatch && !url && (emojiHash.hasOwnProperty(noToneMatch[1]) || aliasHash.hasOwnProperty(noToneMatch[1]))) { if (noToneMatch && !url && (emojiHash.hasOwnProperty(noToneMatch[1]) || aliasHash.hasOwnProperty(noToneMatch[1]))) {
url = opts.getURL(`/images/emoji/${opts.emojiSet}/${code.replace(/:t/, '/')}.png`); url = opts.getURL(`/images/emoji/${opts.emojiSet}/${code.replace(/:t/, '/')}.png`);
} }

View File

@ -49,7 +49,7 @@ function rule(state, startLine, endLine) {
let oldParentType = state.parentType; let oldParentType = state.parentType;
state.parentType = 'paragraph'; state.parentType = 'paragraph';
token = state.push('paragraph_open', 'p', 0); token = state.push('paragraph_open', 'p', 1);
token.map = [startLine, state.line]; token.map = [startLine, state.line];
token = state.push('inline', '', 0); token = state.push('inline', '', 0);

View File

@ -561,19 +561,15 @@ describe PrettyText do
html = <<~HTML html = <<~HTML
<p>a <img><br> <p>a <img><br>
<img></p> <img></p>
<p> <p><img><br>
<img><br>
<img></p>
<p>
<img></p> <img></p>
<p><img></p>
<p>a</p> <p>a</p>
<p> <p><img></p>
<img></p>
<ul> <ul>
<li>li</li> <li>li</li>
</ul> </ul>
<p> <p><img></p>
<img></p>
<pre><code class="lang-auto">test <pre><code class="lang-auto">test
</code></pre> </code></pre>
<pre><code class="lang-auto">test <pre><code class="lang-auto">test
@ -600,8 +596,7 @@ describe PrettyText do
HTML HTML
html = <<~HTML html = <<~HTML
<p> <p><img><br>
<img><br>
<img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br>
<img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"><br>
<img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"></p> <img src="https://awesome.cdn/original/9/9/99c9384b8b6d87f8509f8395571bc7512ca3cad1.jpg"></p>
@ -661,6 +656,9 @@ describe PrettyText do
expect(PrettyText.cook("hello 🤷‍♀️")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_shrugging.png?v=5\" title=\":woman_shrugging:\" class=\"emoji\" alt=\":woman_shrugging:\"></p>") expect(PrettyText.cook("hello 🤷‍♀️")).to eq("<p>hello <img src=\"/images/emoji/twitter/woman_shrugging.png?v=5\" title=\":woman_shrugging:\" class=\"emoji\" alt=\":woman_shrugging:\"></p>")
end end
it "should not treat a non emoji as an emoji" do
expect(PrettyText.cook(':email,class_name:')).not_to include('emoji')
end
it "supports href schemes" do it "supports href schemes" do
SiteSetting.allowed_href_schemes = "macappstore|steam" SiteSetting.allowed_href_schemes = "macappstore|steam"
@ -791,6 +789,7 @@ HTML
expect(PrettyText.cook(" http://a.com")).not_to include('onebox') expect(PrettyText.cook(" http://a.com")).not_to include('onebox')
expect(PrettyText.cook("a\n http://a.com")).not_to include('onebox') expect(PrettyText.cook("a\n http://a.com")).not_to include('onebox')
expect(PrettyText.cook("sam@sam.com")).not_to include('onebox') expect(PrettyText.cook("sam@sam.com")).not_to include('onebox')
expect(PrettyText.cook("<img src='a'>\nhttp://a.com")).to include('onebox')
end end
it "can handle bbcode" do it "can handle bbcode" do