spec/postrank-uri_spec.rb in postrank-uri-1.0.17 vs spec/postrank-uri_spec.rb in postrank-uri-1.0.18
- old
+ new
@@ -27,20 +27,24 @@
context "accept improperly escaped PostRank::URI strings" do
# See http://tools.ietf.org/html/rfc3986#section-2.3
it "should unescape PostRank::URI with spaces encoded as '+'" do
- PostRank::URI.unescape('id=+1').should == 'id= 1'
+ PostRank::URI.unescape('?id=+1').should == '?id= 1'
end
it "should unescape PostRank::URI with spaces encoded as '+'" do
- PostRank::URI.unescape('id%3D+1').should == 'id= 1'
+ PostRank::URI.unescape('?id%3D+1').should == '?id= 1'
end
it "should unescape PostRank::URI with spaces encoded as %20" do
- PostRank::URI.unescape('id=%201').should == 'id= 1'
+ PostRank::URI.unescape('?id=%201').should == '?id= 1'
end
+
+ it "should not unescape '+' to spaces in paths" do
+ PostRank::URI.unescape('/foo+bar?id=foo+bar').should == '/foo+bar?id=foo bar'
+ end
end
end
context "normalize" do
@@ -98,11 +102,11 @@
end
context "canonicalization" do
def c(uri)
- PostRank::URI.c18n(uri).to_s
+ PostRank::URI.c14n(uri).to_s
end
context "query parameters" do
it "should handle nester parameters" do
c('igvita.com/?id=a&utm_source=a').should == 'http://igvita.com/?id=a'
@@ -120,10 +124,16 @@
it "should remove awesm/sms parameters" do
c('igvita.com/?id=a&utm_source=a&awesm=b').should == 'http://igvita.com/?id=a'
c('igvita.com/?id=a&sms_ss=a').should == 'http://igvita.com/?id=a'
end
+
+ it "should remove PHPSESSID parameter" do
+ c('http://www.nachi.org/forum?PHPSESSID=9ee2fb10b7274ef2b15d1d4006b8c8dd').should == 'http://www.nachi.org/forum?'
+ c('http://www.nachi.org/forum/?PHPSESSID=9ee2fb10b7274ef2b15d1d4006b8c8dd').should == 'http://www.nachi.org/forum/?'
+ c('http://www.nachi.org/forum?id=123&PHPSESSID=9ee2fb10b7274ef2b15d1d4006b8c8dd').should == 'http://www.nachi.org/forum?id=123'
+ end
end
context "hashbang" do
it "should rewrite twitter links to crawlable versions" do
c('http://twitter.com/#!/igrigorik').should == 'http://twitter.com/igrigorik'
@@ -160,11 +170,11 @@
context "clean" do
def c(uri)
PostRank::URI.clean(uri)
end
- it "should unescape, c18n and normalize" do
+ it "should unescape, c14n and normalize" do
c('http://igvita.com/?id=1').should == 'http://igvita.com/?id=1'
c('igvita.com/?id=1').should == 'http://igvita.com/?id=1'
c('http://igvita.com/?id= 1').should == 'http://igvita.com/?id=%201'
c('http://igvita.com/?id=+1').should == 'http://igvita.com/?id=%201'
@@ -177,11 +187,11 @@
c('test.tumblr.com/post/23223/text-stub').should == 'http://test.tumblr.com/post/23223'
end
it "should clean host specific parameters" do
- YAML.load_file('spec/c18n_hosts.yml').each do |orig, clean|
+ YAML.load_file('spec/c14n_hosts.yml').each do |orig, clean|
c(orig).should == clean
end
end
end
@@ -347,8 +357,16 @@
PostRank::URI.valid?('http://www.test.c').should be_false
end
it 'marks www.test.com as valid' do
PostRank::URI.valid?('http://www.test.com').should be_true
+ end
+
+ it 'marks Unicode domain as valid (NOTE: works only with a scheme)' do
+ PostRank::URI.valid?('http://президент.рф').should be_true
+ end
+
+ it 'marks punycode domain domain as valid' do
+ PostRank::URI.valid?('xn--d1abbgf6aiiy.xn--p1ai').should be_true
end
end
end