Skip to content

Commit

Permalink
fix: upcase body before searching to find lowercase tracking numbers (#…
Browse files Browse the repository at this point in the history
…85)

The regexps define the search pattern in terms of uppercase characters,
so when the source data you're searching contains lowercase tracking
numbers, they don't match.

By upcasing the body before searching, it's more likely to match the
search patterns.

This also matches that initializing a new `TrackingNumber` object
upcases the number for its internal value.

Inspired by:
jkeen/tracking_number_data#102

Meant as an interim solution until it's decided whether the source
regexps should be case-sensitive or not.
  • Loading branch information
cgunther committed Aug 20, 2024
1 parent f04ea42 commit e07c754
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/tracking_number/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def self.scan(body)
# matches with match groups within the match data
matches = []

body.scan(const_get(:SEARCH_PATTERN)) do
body.upcase.scan(const_get(:SEARCH_PATTERN)) do
# get the match data instead, which is needed with these types of regexes
matches << $~
end
Expand Down
8 changes: 7 additions & 1 deletion test/tracking_number_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class TrackingNumberTest < Minitest::Test
assert_equal 1, s.size
assert_equal "1Z879E930346834440", s.first.tracking_number
end

should "return tracking numbers entered as lowercase" do
s = TrackingNumber.search("hello 1z879E930346834440 bye")
assert_equal 1, s.size
assert_equal "1Z879E930346834440", s.first.tracking_number
end
end

context "tracking number additional data for ups" do
Expand Down Expand Up @@ -201,7 +207,7 @@ class TrackingNumberTest < Minitest::Test
context "searching numbers that have partners" do
partnership_number = "420 11213 92 6129098349792366623 8"
single_number = "92001903060085300042901077"

search_string = ["number that matches two services", partnership_number, " number that matches only one: ", single_number, "let's see if that does it"].join(' ')

should "match only carriers by default" do
Expand Down

0 comments on commit e07c754

Please sign in to comment.