1 # frozen_string_literal: true
5 class InvalidCharsValidatable
6 include ActiveModel::Validations
8 validates :chars, :characters => true
12 class InvalidUrlCharsValidatable
13 include ActiveModel::Validations
15 validates :chars, :characters => { :url_safe => true }
19 class CharactersValidatorTest < ActiveSupport::TestCase
20 include Rails::Dom::Testing::Assertions::SelectorAssertions
22 def test_with_valid_chars
23 c = InvalidCharsValidatable.new
25 valid = ["Name.", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
26 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲", "/;.,?%#"]
30 assert_predicate c, :valid?, "'#{v}' should be valid"
34 def test_with_invalid_chars
35 c = InvalidCharsValidatable.new
37 invalid = ["\x7f<hr/>", "test@example.com\x0e-", "s/\x1ff", "aa/\ufffe",
38 "aa\x0b-,", "aa?\x08", "/;\uffff.,?", "\x00-も対応します/", "\x0c#ping",
39 "foo\x1fbar", "foo\x7fbar", "foo\ufffebar", "foo\uffffbar"]
43 assert_not_predicate c, :valid?, "'#{v}' should not be valid"
47 def test_with_valid_url_chars
48 c = InvalidUrlCharsValidatable.new
50 valid = ["Name", "'me", "he\"", "<hr>", "*ho", "\"help\"@",
51 "vergrößern", "ルシステムにも対応します", "輕觸搖晃的遊戲"]
55 assert_predicate c, :valid?, "'#{v}' should be valid"
59 def test_with_invalid_url_chars
60 c = InvalidUrlCharsValidatable.new
62 invalid = ["Name.", "you;me", "he\"#", "<hr/>", "50%", "good?",
63 "vergrößern,deutsche", "ルシステムに;.も対応します", "輕觸搖/晃的遊戲", "/;.,?%#"]
67 assert_not_predicate c, :valid?, "'#{v}' should not be valid"