Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #354
- Loading branch information
Showing
6 changed files
with
52 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'uri' | ||
module UrlHelper | ||
def url_valid?(url) | ||
url = begin | ||
URI.parse(url) | ||
rescue StandardError | ||
false | ||
end | ||
url.is_a?(URI::HTTP) || url.is_a?(URI::HTTPS) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'rails_helper' | ||
|
||
describe UrlHelper, type: :helper do | ||
describe '#url_valid' do | ||
context 'when url valid called' do | ||
it 'return if valid url passed' do | ||
expect(helper.url_valid?('https://app.chatwoot.com/')).to eq true | ||
end | ||
|
||
it 'return false if invalid url passed' do | ||
expect(helper.url_valid?('javascript:alert(document.cookie)')).to eq false | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters