
Security News
Follow-up and Clarification on Recent Malicious Ruby Gems Campaign
A clarification on our recent research investigating 60 malicious Ruby gems.
A simple Ruby module that provides basic URL operations.
This implementation supports:
obj.join(component)
instead of MODULE.join(obj, component)
)obj('a/b').join('c')
returns a/b/c
not a/c
)This gem does not try to be RFC compliant when joining URLs.
Given that the majority of other implementations all do some degree of shenanigans when joining URLs it's assumed that a/b/c
+ d
= a/d
is buried in a spec somewhere.
This library does not do that, it does a/b/c
+ d
= a/b/c/d
, which is what is needed in 99% of cases.
If you need full RFC compliance this gem is not suitable.
require 'basic_url'
base_url = BasicUrl.parse('192.0.2.64/api/v1', default_protocol: 'https')
puts(base_url.path)
# api/v1
# Basic joining, returns a new object
# join! is also available to update the current object
controller = base_url.join('some/controller')
puts controller.path
# api/v1/some/controller
# By default absolute paths replace
controller = base_url.join('/some/controller')
puts controller.path
# some/controller
# But this is selectable
controller = base_url.join('/some/controller', replace_when_absolute: false)
puts controller.path
# api/v1/some/controller
# To get a URL string call .to_s
puts controller.to_s
# https://192.0.2.64/api/v1/some/controller
# Path components are URL encoded by default
puts BasicUrl.new(protocol: 'http', host: 'foo.local', path: '/api/v0/some path/with spaces', params: { key: 'value:1', key2: 'Value!', key3: ['and', 'arrays']}).to_s
# http://foo.local/api/v0/some+path/with+spaces?key=value%3A1&key2=Value%21&key3[]=and&key3[]=arrays
# Query parameters can also be added with params=. This modifies the object
controller = base_url.join('some/controller')
controller.params = { key1: 'val1' }
controller.params[:key2] = 'val2'
puts controller.to_s
# https://192.0.2.64/api/v1/some/controller?key1=val1&key2=val2
# Pass enforce_trailing_path_slash: true to to_s to always include a trailing / on the path parameter
puts base_url.to_s(enforce_trailing_path_slash: true)
# https://192.0.2.64/api/v1/
All support is through Github issues. Questions, bug reports and pull requests are accepted at https://github.com/TJNII/basic_url.
This is an opinionated project, the author was finally annoyed enough by using Pathname to join URL components to publish this.
This project will not support the a + b + c + d = d
behavior of other implementations, if you require that perhaps Adressable::URI would be better.
For the quickest response please add a test case.
Hope this helped you, have a good day.
FAQs
Unknown package
We found that basic_url demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A clarification on our recent research investigating 60 malicious Ruby gems.
Security News
ESLint now supports parallel linting with a new --concurrency flag, delivering major speed gains and closing a 10-year-old feature request.
Research
/Security News
A malicious Go module posing as an SSH brute forcer exfiltrates stolen credentials to a Telegram bot controlled by a Russian-speaking threat actor.