From 05582790c88e9867743388b7b941adc51ac05e60 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 5 Mar 2018 14:38:46 +0530 Subject: [PATCH 1/3] allow underscores in usernames --- lib/jekyll-mentions.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/jekyll-mentions.rb b/lib/jekyll-mentions.rb index d45153c..ae80582 100644 --- a/lib/jekyll-mentions.rb +++ b/lib/jekyll-mentions.rb @@ -38,10 +38,7 @@ def filter_with_mention(src) end def mention_username_pattern - Regexp.new( - HTML::Pipeline::MentionFilter::UsernamePattern.source, - Regexp::IGNORECASE - ) + @mention_username_pattern ||= %r![\w][\w_-]*! end # Public: Filters hash where the key is the mention base URL. From c08c7d2d0f1f8e0786ab8dfd98e08c3f83c72638 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Mon, 5 Mar 2018 16:20:12 +0530 Subject: [PATCH 2/3] test behavior with hyphens and underscores --- spec/fixtures/_docs/special_characters.md | 11 +++++++++++ spec/mentions_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 spec/fixtures/_docs/special_characters.md diff --git a/spec/fixtures/_docs/special_characters.md b/spec/fixtures/_docs/special_characters.md new file mode 100644 index 0000000..80a0b02 --- /dev/null +++ b/spec/fixtures/_docs/special_characters.md @@ -0,0 +1,11 @@ +--- +title: Unconventional Names +--- + +Howdy @-pardner! + +@haTTric- sez you are quite the @task-master.. + +Checkout @Casino_Royale + +The Original @_Bat_Cave diff --git a/spec/mentions_spec.rb b/spec/mentions_spec.rb index 9873fa8..9265568 100644 --- a/spec/mentions_spec.rb +++ b/spec/mentions_spec.rb @@ -25,6 +25,7 @@ let(:basic_doc) { find_by_title(site.collections["docs"].docs, "File") } let(:doc_with_liquid) { find_by_title(site.collections["docs"].docs, "With Liquid") } let(:txt_doc) { find_by_title(site.collections["docs"].docs, "Don't Touch Me") } + let(:spl_chars_doc) { find_by_title(site.collections["docs"].docs, "Unconventional Names") } def para(content) "

#{content}

" @@ -79,6 +80,28 @@ def para(content) ) end + context "with non-word characters" do + it "does not render when there's a leading hyphen" do + expect(spl_chars_doc.output).to start_with(para("Howdy @-pardner!")) + end + + it "renders fine when there's a non-leading hyphen" do + expect(spl_chars_doc.output).to include(para( + "@haTTric- sez you are quite " \ + "the @task-master.." + )) + end + + it "renders fine when there's an underscore" do + expect(spl_chars_doc.output).to include(para( + "Checkout @Casino_Royale" + )) + expect(spl_chars_doc.output).to include(para( + "The Original @_Bat_Cave" + )) + end + end + context "with a different base for jmentions" do let(:mentions_src) { "http://mine.club" } let(:config_overrides) do From 068dc75c8f6cd6e4ab3a4fb572f7c2475450dedf Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Wed, 7 Mar 2018 20:20:05 +0530 Subject: [PATCH 3/3] underscore is included as part of /\w/ metachar --- lib/jekyll-mentions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll-mentions.rb b/lib/jekyll-mentions.rb index ae80582..f8472ae 100644 --- a/lib/jekyll-mentions.rb +++ b/lib/jekyll-mentions.rb @@ -38,7 +38,7 @@ def filter_with_mention(src) end def mention_username_pattern - @mention_username_pattern ||= %r![\w][\w_-]*! + @mention_username_pattern ||= %r![\w][\w-]*! end # Public: Filters hash where the key is the mention base URL.