Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a URL is the whole query string or fragment, recognize as data_typ… #147

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions unfurl/parsers/parse_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ def run(unfurl, node):
data_type='url.query.pair', key=key, value=v, label=f'{key}: {v}',
parent_id=node.node_id, incoming_edge_config=urlparse_edge)

# If the query string or fragment is actually another URL (as seen in some redirectors), we want to
# continue doing subsequent parsing on it. For that, we need to recognize it and change the data_type to url.
if not parsed_qs:
try:
parsed_url = urllib.parse.urlparse(node.value)
if (parsed_url.netloc and parsed_url.path) or (parsed_url.scheme and parsed_url.netloc):
unfurl.add_to_queue(
data_type='url', key=None, value=node.value, parent_id=node.node_id,
incoming_edge_config=urlparse_edge)
return
except:
# Guess it wasn't a URL
pass

elif node.data_type == 'url.params':
split_params_re = re.compile(r'^(?P<key>[^=]+?)=(?P<value>[^=?]+)(?P<delim>[;,|])')
split_params = split_params_re.match(node.value)
Expand Down