Skip to content

Commit

Permalink
Merge pull request #1980 from robinboening/allow_pound_sign_in_legacy…
Browse files Browse the repository at this point in the history
…_url

Allow pound sign in legacy url
  • Loading branch information
tvdeyen authored Dec 12, 2020
2 parents c7cde4f + 295294c commit 2f60295
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/models/alchemy/legacy_page_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ class Alchemy::LegacyPageUrl < ActiveRecord::Base

validates :urlname,
presence: true,
format: {with: /\A[:\.\w\-+_\/\?&%;=]*\z/}
format: {with: /\A[:\.\w\-+_\/\?&%;=#]*\z/}
end
24 changes: 16 additions & 8 deletions spec/models/alchemy/legacy_page_url_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@
describe Alchemy::LegacyPageUrl do
let(:page) { build_stubbed(:alchemy_page) }

let(:page_url_with_parameters) do
Alchemy::LegacyPageUrl.new(urlname: "index.php?id=2", page: page)
it "is invalid with invalid URL characters" do
expect(
described_class.new(urlname: "<foo>{bar}", page: page)
).to be_invalid
end

let(:valid_page_url) do
Alchemy::LegacyPageUrl.new(urlname: "my/0-work+is-nice_stuff", page: page)
it "is valid with correct urlname format" do
expect(
described_class.new(urlname: "my/0-work+is-nice_stuff", page: page)
).to be_valid
end

it "is only valid with correct urlname format" do
expect(valid_page_url).to be_valid
it "is valid with get parameters in urlname" do
expect(
described_class.new(urlname: "index.php?id=2", page: page)
).to be_valid
end

it "is also valid with get parameters in urlname" do
expect(page_url_with_parameters).to be_valid
it "is valid with pound sign in urlname" do
expect(
described_class.new(urlname: "with#anchor", page: page)
).to be_valid
end
end

0 comments on commit 2f60295

Please sign in to comment.