is_valid_scheme is missing an end anchor, so invalid schemes are accepted and URLs mis-parsed

Open Beginner friendly
#192 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
backend

Research direction

Start by locating is_valid_scheme and compare its regex with the module's other validators, which use both anchors. Reproduce the issue with furl('a b:c'), then verify that invalid schemes leave the whole input as the path while valid schemes continue to parse correctly.

Written by the indexing model from the issue text.

Description

Summary

is_valid_scheme matches the scheme regex with re.match, but the pattern lacks a trailing $ anchor — unlike the module's other validators, which use ^...$. Any string whose prefix looks like a scheme is therefore accepted, so a URL like a b:c is mis-parsed as scheme a b + path c, instead of no scheme and path a b:c.

Reproduction
from furl import furl
f = furl('a b:c')
print(f.scheme)      # 'a b'   <- expected None
print(str(f.path))   # 'c'     <- expected 'a b:c'
Expected

a b is not a valid scheme (it contains a space), so f.scheme is None and the whole string is the path.

Actual

Scheme 'a b' is extracted and stored; the parse is corrupted.

Fix sketch

Anchor the scheme regex with $ (or use re.fullmatch), matching the module's other validators.

Environment

furl 2.1.4 (master @ 46d9ea7), Python 3.12.

Dominant language
Python
Stars
2.8k
Forks
167
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from gruns/furl

All issues in gruns/furl

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.