-
Notifications
You must be signed in to change notification settings - Fork 1
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
Twingly::URL::Utilities.remove_scheme #21
Conversation
Test and code from Zambezi. A minor version bump is needed if merged. Close #6
LGTM, extensive test suite! |
What do you think about this? $ git diff lib
diff --git a/lib/twingly/url/utilities.rb b/lib/twingly/url/utilities.rb
index cb0c33d..8e1800a 100644
--- a/lib/twingly/url/utilities.rb
+++ b/lib/twingly/url/utilities.rb
@@ -3,10 +3,10 @@ module Twingly
module Utilities
module_function
- PROTOCOL_EXPRESSION = /^https?:/i
+ PROTOCOL_EXPRESSION = /https?:/i
def remove_scheme(url)
- url.gsub(PROTOCOL_EXPRESSION, '')
+ url.sub(PROTOCOL_EXPRESSION, '')
end
end
end (All tests pass) |
And what do you think of these additional tests? $ git diff test
diff --git a/test/unit/utilities_test.rb b/test/unit/utilities_test.rb
index 94d5d04..32232dc 100644
--- a/test/unit/utilities_test.rb
+++ b/test/unit/utilities_test.rb
@@ -57,5 +57,19 @@ class TestUtilities < MiniTest::Unit::TestCase
result = Twingly::URL::Utilities.remove_scheme(url)
assert_equal '//www.thecloset.gr/people/bloggers-pick-ιωάννα-τσιγαρίδα', result
end
+
+ should "only remove scheme from HTTP URL" do
+ url = 'http://feedjira.herokuapp.com/?url=http://developer.twingly.com/feed.xml'
+
+ result = Twingly::URL::Utilities.remove_scheme(url)
+ assert_equal '//feedjira.herokuapp.com/?url=http://developer.twingly.com/feed.xml', result
+ end
+
+ should "only remove scheme from HTTPS URL" do
+ url = 'https://feedjira.herokuapp.com/?url=https://signalvnoise.com/posts.rss'
+
+ result = Twingly::URL::Utilities.remove_scheme(url)
+ assert_equal '//feedjira.herokuapp.com/?url=https://signalvnoise.com/posts.rss', result
+ end
end
end |
Can't see where it'd go wrong, guess it's more performant too, which I like.
Good ones! |
The Ruby Style Guide says that |
I thought about this again, if we have
|
True. |
Test case for that: should "not remove scheme from non HTTP(S) URLs with parameter" do
url = 'ftp://ftp.example.com/?url=https://www.example.com/'
result = Twingly::URL::Utilities.remove_scheme(url)
assert_equal 'ftp://ftp.example.com/?url=https://www.example.com/', result
end |
@dentarg I think the proposed changes are good! Keep the |
The tests are from Zambezi, just replaced |
We only need to replace the first occurrence. Should make the code more clear. May perform better.
Done. |
👍 |
Twingly::URL::Utilities.remove_scheme
Test and code from Zambezi. A minor version bump is needed if merged.
Close #6