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

Fix logic to detect URLs #122

Merged
merged 6 commits into from
May 4, 2022
Merged

Fix logic to detect URLs #122

merged 6 commits into from
May 4, 2022

Conversation

simleo
Copy link
Collaborator

@simleo simleo commented May 4, 2022

utils.is_url currently returns False if the netloc field is empty, causing two main problems:

  • Failure to recognize mailto: entity IDs as absolute URLs, which results in a leading hash mark being added to the ID
  • Incorrect handling of URLs like file:///tmp/foo.txt, which are treated as relative paths

In the latter case, the following call:

crate.add_file("file:///tmp/foo.txt")

Results in an output entry of:

{
    "@id": "foo.txt",
    "@type": "File"
},

Though no file is added to the crate dir (see #75) unless the current working directory has a file:/tmp/foo.txt file in it (file: is a legal directory path in some OSs, e.g. Linux).

With this PR, the generated file entry is:

{
    "@id": "file:///tmp/foo.txt",
    "@type": "File"
},

Note that it's still possible to add a file whose relative (to the CWD) path is file:/tmp/foo.txt (or similar) by passing its absolute path to add_file.

@simleo simleo merged commit 854ba36 into master May 4, 2022
@simleo simleo deleted the fix_is_url branch May 4, 2022 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant