Skip to content

bug: /#/ in URLs is failing validation #288

Closed

Description

@adrienthiery

Hi there,
following #285 's report, we also saw a regression on testing validity or a URL, namely https://exchange.jetswap.finance/#/swap ( ValidationError(func=url, args={'value': 'https://exchange.jetswap.finance/#/swap'})

The /#/ in there is probably the thing making it match as invalid, sadly it is a common side-effect of some JS UI libraries.

As the last comments mention, it would indeed be super nice to follow the common semver practice in bumping a major version in case of breaking change, and at least mention in the releases description when a breaking change is included. 🙏

Activity

  1. nandgator commented on Aug 17, 2023

    @nandgator
    Collaborator

    The /#/ in there is probably the thing making it match as invalid, sadly it is a common side-effect of some JS UI libraries.

    Hi @adrienthiery, indeed, /#/ was causing trouble, but this was not an intentional breaking change, unlike the case in #285 (comment). It is an edge case which was neither present in the tests before nor after v0.20.0. But since the validation algorithm changed, the edge case popped up.

    Currently src/validators/url.py has:

    if fragment:
    optional_segments &= all(char_to_avoid not in fragment for char_to_avoid in ("/", "?"))

    When the URL https://exchange.jetswap.finance/#/swap is passed, fragment = /swap, which makes optional_segments = false since / is present in the fragment, which is (an) unusual (side-effect) as you suggest.


    Here's the patch.

        if fragment:
    +      fragment = fragment.lstrip("/") if fragment.startswith("/") else fragment
            optional_segments &= all(char_to_avoid not in fragment for char_to_avoid in ("/", "?")

    This will handle all the URLs with /#/some-value fragment in them, but I think there will be more edge cases, only time will tell. PRs are welcome!

  2. changed the title [-]Breaking change between 0.20 and latest version (URLs including `/#/`)[/-] [+]bug: `/#/` in URLs is failing validation[/+] on Aug 17, 2023
  3. cfi-gb commented on Sep 6, 2023

    @cfi-gb

    but I think there will be more edge cases, only time will tell.

    It seems a few additional ones have been found so far and #296 has been raised as a follow-up with additional different examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugIssue: Works not as designed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions