mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
store the slug as the title is, only sanitize the slug
and prettify code
This commit is contained in:
committed by
fantasticfears
parent
b772ff6e13
commit
a48dd1cc28
@@ -10,15 +10,15 @@ describe Slug do
|
||||
before { SiteSetting.slug_generation_method = 'ascii' }
|
||||
|
||||
it 'generates the slug' do
|
||||
expect(Slug.for("hello world", 'topic')).to eq('hello-world')
|
||||
expect(Slug.for("hello world")).to eq('hello-world')
|
||||
end
|
||||
|
||||
it 'generates default slug when nothing' do
|
||||
expect(Slug.for('', 'topic')).to eq('topic')
|
||||
expect(Slug.for('')).to eq('topic')
|
||||
end
|
||||
|
||||
it "doesn't generate slugs that are just numbers" do
|
||||
expect(Slug.for('123', 'topic')).to eq('topic')
|
||||
expect(Slug.for('123')).to eq('topic')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,15 +27,15 @@ describe Slug do
|
||||
after { SiteSetting.slug_generation_method = 'ascii' }
|
||||
|
||||
it 'generates the slug' do
|
||||
expect(Slug.for("熱帶風暴畫眉", 'topic')).to eq('%E7%86%B1%E5%B8%B6%E9%A2%A8%E6%9A%B4%E7%95%AB%E7%9C%89')
|
||||
expect(Slug.for("熱帶風暴畫眉")).to eq('熱帶風暴畫眉')
|
||||
end
|
||||
|
||||
it 'generates default slug when nothing' do
|
||||
expect(Slug.for('', 'topic')).to eq('topic')
|
||||
expect(Slug.for('')).to eq('topic')
|
||||
end
|
||||
|
||||
it "doesn't generate slugs that are just numbers" do
|
||||
expect(Slug.for('123', 'topic')).to eq('topic')
|
||||
expect(Slug.for('123')).to eq('topic')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,9 +45,9 @@ describe Slug do
|
||||
|
||||
it 'generates the slug' do
|
||||
expect(Slug.for("hello world", 'category')).to eq('category')
|
||||
expect(Slug.for("hello world", 'topic')).to eq('topic')
|
||||
expect(Slug.for('', 'topic')).to eq('topic')
|
||||
expect(Slug.for('123', 'topic')).to eq('topic')
|
||||
expect(Slug.for("hello world")).to eq('topic')
|
||||
expect(Slug.for('')).to eq('topic')
|
||||
expect(Slug.for('123')).to eq('topic')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -111,14 +111,15 @@ describe Slug do
|
||||
after { SiteSetting.slug_generation_method = 'ascii' }
|
||||
|
||||
it 'generates precentage encoded string' do
|
||||
expect(Slug.encoded_generator("Jeff hate's !~-_|,=#this")).to eq("Jeff-hates-%7E-_%7Cthis")
|
||||
expect(Slug.encoded_generator("뉴스피드")).to eq("%EB%89%B4%EC%8A%A4%ED%94%BC%EB%93%9C")
|
||||
expect(Slug.encoded_generator("آموزش اضافه کردن لینک اختیاری به هدر")).to eq("%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%D8%A7%D8%B6%D8%A7%D9%81%D9%87-%DA%A9%D8%B1%D8%AF%D9%86-%D9%84%DB%8C%D9%86%DA%A9-%D8%A7%D8%AE%D8%AA%DB%8C%D8%A7%D8%B1%DB%8C-%D8%A8%D9%87-%D9%87%D8%AF%D8%B1")
|
||||
expect(Slug.encoded_generator("熱帶風暴畫眉")).to eq("%E7%86%B1%E5%B8%B6%E9%A2%A8%E6%9A%B4%E7%95%AB%E7%9C%89")
|
||||
expect(Slug.encoded_generator("Jeff hate's !~-_|,=#this")).to eq("Jeff-hates-this")
|
||||
expect(Slug.encoded_generator("뉴스피드")).to eq("뉴스피드")
|
||||
expect(Slug.encoded_generator("آموزش اضافه کردن لینک اختیاری به هدر")).to eq("آموزش-اضافه-کردن-لینک-اختیاری-به-هدر")
|
||||
expect(Slug.encoded_generator("熱帶風暴畫眉")).to eq("熱帶風暴畫眉")
|
||||
end
|
||||
|
||||
it 'reject RFC 3986 reserved character and blank' do
|
||||
expect(Slug.encoded_generator(":/?#[]@!$ &'()*+,;=")).to eq("")
|
||||
expect(Slug.encoded_generator(":/?#[]@!$ &'()*+,;=% -_`~.")).to eq("")
|
||||
expect(Slug.encoded_generator(" - English and Chinese title with special characters / 中文标题 !@:?\\:'`#^& $%&*()` -- ")).to eq("English-and-Chinese-title-with-special-characters-中文标题")
|
||||
end
|
||||
|
||||
it 'generates null when nothing' do
|
||||
|
||||
@@ -209,8 +209,8 @@ describe Category do
|
||||
end
|
||||
|
||||
it "creates a slug" do
|
||||
expect(@category.slug).to eq("%E6%B5%8B%E8%AF%95")
|
||||
expect(@category.slug_for_url).to eq("%E6%B5%8B%E8%AF%95")
|
||||
expect(@category.slug).to eq("测试")
|
||||
expect(@category.slug_for_url).to eq("测试")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -19,15 +19,15 @@ describe Topic do
|
||||
after { SiteSetting.slug_generation_method = 'ascii' }
|
||||
|
||||
it "returns a Slug for a title" do
|
||||
Slug.expects(:for).with(title, 'topic').returns(slug)
|
||||
Slug.expects(:for).with(title).returns(slug)
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq(slug)
|
||||
end
|
||||
|
||||
context 'for cjk characters' do
|
||||
let(:title) { "熱帶風暴畫眉" }
|
||||
let(:slug) { "%E7%86%B1%E5%B8%B6%E9%A2%A8%E6%9A%B4%E7%95%AB%E7%9C%89" }
|
||||
let(:slug) { "熱帶風暴畫眉" }
|
||||
it "returns encoded Slug for a title" do
|
||||
Slug.expects(:for).with(title, 'topic').returns(slug)
|
||||
Slug.expects(:for).with(title).returns(slug)
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq(slug)
|
||||
end
|
||||
end
|
||||
@@ -36,7 +36,7 @@ describe Topic do
|
||||
let(:title) { "123456789" }
|
||||
let(:slug) { "topic" }
|
||||
it 'generates default slug' do
|
||||
Slug.expects(:for).with(title, 'topic').returns("topic")
|
||||
Slug.expects(:for).with(title).returns("topic")
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq("topic")
|
||||
end
|
||||
end
|
||||
@@ -49,7 +49,7 @@ describe Topic do
|
||||
let(:slug) { "topic" }
|
||||
|
||||
it "returns a Slug for a title" do
|
||||
Slug.expects(:for).with(title, 'topic').returns('topic')
|
||||
Slug.expects(:for).with(title).returns('topic')
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq(slug)
|
||||
end
|
||||
end
|
||||
@@ -57,7 +57,7 @@ describe Topic do
|
||||
context '#ascii_generator' do
|
||||
before { SiteSetting.slug_generation_method = 'ascii' }
|
||||
it "returns a Slug for a title" do
|
||||
Slug.expects(:for).with(title, 'topic').returns(slug)
|
||||
Slug.expects(:for).with(title).returns(slug)
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq(slug)
|
||||
end
|
||||
|
||||
@@ -65,7 +65,7 @@ describe Topic do
|
||||
let(:title) { "熱帶風暴畫眉" }
|
||||
let(:slug) { 'topic' }
|
||||
it "returns 'topic' when the slug is empty (say, non-latin characters)" do
|
||||
Slug.expects(:for).with(title, 'topic').returns("topic")
|
||||
Slug.expects(:for).with(title).returns("topic")
|
||||
expect(Fabricate.build(:topic, title: title).slug).to eq("topic")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user