Skip to content

Commit

Permalink
feat(integrations): Update regex to match multiple urls (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
captainJackDnaiel authored Jan 22, 2025
1 parent 14b8e43 commit e308884
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion registry/tracecat_registry/base/etl/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from tracecat_registry import registry

# Improved regular expression to match URLs including paths and query parameters
URL_REGEX = r'https?://(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,6}(?:/[^\s"\'\],\.]*)?'
URL_REGEX = r'https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*)(?<![?&=/#.])'


@registry.register(
Expand Down
24 changes: 17 additions & 7 deletions tests/registry/test_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def test_extract_ipv4_addresses(texts, expected_ip_addresses):
"Visit our website at https://example.com for more info.",
["https://example.com"],
),
(
"This url was secured: https://secure.url/nX-BpUKr17mePOHRS5_IUlHEPW//https%3A%2F%2Fmyurl.com",
["https://secure.url/nX-BpUKr17mePOHRS5_IUlHEPW//https%3A%2F%2Fmyurl.com"],
),
(
"<p>Click on this link: <a href='https://www.exemple.com/SUB' target='_blank'>https://www.exemple.com/SUB</a></p>",
["https://www.exemple.com/SUB"],
),
(
["Visit our website at https://example.com for more info."],
["https://example.com"],
Expand Down Expand Up @@ -155,13 +163,15 @@ def test_extract_ipv4_addresses(texts, expected_ip_addresses):
),
],
ids=[
"single_url",
"multiple_urls",
"no_urls",
"invalid_and_valid_url_with_path",
"multiple_urls_in_text_with_paths",
"json_with_urls_and_paths",
"no_urls",
"single_url_string",
"single_url_with_encoded_path",
"single_url_in_html",
"single_url_in_list",
"two_urls_in_list",
"filter_invalid_url",
"multiple_urls_in_text",
"urls_in_json_string",
"empty_result"
],
)
def test_extract_urls(texts, expected_urls):
Expand Down

0 comments on commit e308884

Please sign in to comment.