Skip to content

Commit

Permalink
Replace A-Za-z with [:alpha:]
Browse files Browse the repository at this point in the history
  • Loading branch information
jory-graham committed Aug 5, 2021
1 parent 02f759d commit 8ec3649
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/psych/scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def tokenize string

# Check for a String type, being careful not to get caught by hash keys, hex values, and
# special floats (e.g., -.inf).
if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
return string if string.length > 5

if string.match?(/^[^ytonf~]/i)
Expand Down
22 changes: 22 additions & 0 deletions test/psych/test_scalar_scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,27 @@ def test_scan_dot
def test_scan_plus_dot
assert_equal '+.', ss.tokenize('+.')
end

class MatchCallCounter < String
attr_reader :match_call_count

def match?(pat)
@match_call_count ||= 0
@match_call_count += 1
super
end
end

def test_scan_ascii_matches_quickly
ascii = MatchCallCounter.new('abcdefghijklmnopqrstuvwxyz')
ss.tokenize(ascii)
assert_equal 1, ascii.match_call_count
end

def test_scan_unicode_matches_quickly
unicode = MatchCallCounter.new('鳥かご関連用品')
ss.tokenize(unicode)
assert_equal 1, unicode.match_call_count
end
end
end

0 comments on commit 8ec3649

Please sign in to comment.