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

Allow underscores in usernames #57

Merged
merged 3 commits into from
Mar 14, 2018
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
5 changes: 1 addition & 4 deletions lib/jekyll-mentions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/_docs/special_characters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
title: Unconventional Names
---

Howdy @-pardner!

@haTTric- sez you are quite the @task-master..

Checkout @Casino_Royale

The Original @_Bat_Cave
23 changes: 23 additions & 0 deletions spec/mentions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
"<p>#{content}</p>"
Expand Down Expand Up @@ -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(
"<a href=\"https://github.com/haTTric-\" class=\"user-mention\">@haTTric-</a> sez you are quite " \
"the <a href=\"https://github.com/task-master\" class=\"user-mention\">@task-master</a>.."
))
end

it "renders fine when there's an underscore" do
expect(spl_chars_doc.output).to include(para(
"Checkout <a href=\"https://github.com/Casino_Royale\" class=\"user-mention\">@Casino_Royale</a>"
))
expect(spl_chars_doc.output).to include(para(
"The Original <a href=\"https://github.com/_Bat_Cave\" class=\"user-mention\">@_Bat_Cave</a>"
))
end
end

context "with a different base for jmentions" do
let(:mentions_src) { "http://mine.club" }
let(:config_overrides) do
Expand Down