-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
24 additions
and
24 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
require 'strscan' | ||
|
||
class Parsel | ||
class Parsely | ||
VERSION = "0.1.0" | ||
|
||
def self.sanitize(selector) | ||
|
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 |
---|---|---|
@@ -1,58 +1,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'test/unit' | ||
require 'parsel' | ||
require 'parsely' | ||
|
||
class TestParsel < Test::Unit::TestCase | ||
class TestParsely < Test::Unit::TestCase | ||
def test_special_case_single_dash | ||
assert_equal '\\-', Parsel.sanitize('-') | ||
assert_equal '\\-', Parsely.sanitize('-') | ||
end | ||
|
||
def test_null_character | ||
assert_equal "\uFFFD", Parsel.sanitize("\0") | ||
assert_equal "\uFFFD", Parsely.sanitize("\0") | ||
end | ||
|
||
def test_control_characters | ||
input = "\x01\x02\x7F" | ||
expected = "\\1 \\2 \\7f " | ||
assert_equal expected, Parsel.sanitize(input) | ||
assert_equal expected, Parsely.sanitize(input) | ||
end | ||
|
||
def test_first_character_digit | ||
input = '1abc' | ||
expected = "\\31 abc" | ||
assert_equal expected, Parsel.sanitize(input) | ||
assert_equal expected, Parsely.sanitize(input) | ||
end | ||
|
||
def test_second_character_digit_after_dash | ||
input = '-1abc' | ||
expected = "-\\31 abc" | ||
assert_equal expected, Parsel.sanitize(input) | ||
assert_equal expected, Parsely.sanitize(input) | ||
end | ||
|
||
def test_alphanumeric_and_safe_characters | ||
input = 'a-Z_0-9' | ||
assert_equal 'a-Z_0-9', Parsel.sanitize(input) | ||
assert_equal 'a-Z_0-9', Parsely.sanitize(input) | ||
end | ||
|
||
def test_escape_special_characters | ||
input = '!@#$%^&*()' | ||
expected = '\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)' | ||
assert_equal expected, Parsel.sanitize(input) | ||
assert_equal expected, Parsely.sanitize(input) | ||
end | ||
|
||
def test_mixed_input | ||
input = "-1a\x01b\0c!" | ||
expected = "-\\31 a\\1 b�c\\!" | ||
assert_equal expected, Parsel.sanitize(input) | ||
assert_equal expected, Parsely.sanitize(input) | ||
end | ||
|
||
def test_empty_string | ||
assert_equal '', Parsel.sanitize('') | ||
assert_equal '', Parsely.sanitize('') | ||
end | ||
|
||
def test_only_safe_characters | ||
input = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_' | ||
assert_equal input, Parsel.sanitize(input) | ||
assert_equal input, Parsely.sanitize(input) | ||
end | ||
end |