python / python/cpython

is it necessary the urllib.parse._splitnetloc support # and ? in username or password within the netloc?

Open
#118,641 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

type-feature
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:
def _splitnetloc(url: str, start=0):
    delim = len(url)   # position of end of domain part of url, default is end
    **slashlim, queslim, warnlim = [url.find(c, start) for c in '/?#']**
    **if slashlim > queslim or slashlim > warnlim:**    # support the character '#' or '?' in the username or password within the netloc.
        **return url[start:slashlim], url[slashlim:]**
    for c in '/?#':    # look for delimiters; the order is NOT important
        wdelim = url.find(c, start)        # find first of this delim
        if wdelim >= 0:                    # if found
            delim = min(delim, wdelim)     # use earliest delim position
    return url[start:delim], url[delim:]   # return (domain, rest)

the situation from linked the mysql url, e.g., mysql://test123:test#789@127.0.0.1:6313/urlTest?charset=utf8#section1.
when the password has '#' or '?' word in the netloc, it brings exception.
As result of the '/' index value is higher than the '#', I wanna whether it is necessary to level it up.
I suggest a proposal that is the code wrapped by **.
Besides, using the quote/quote_plus/unquote could figure it out. however, it need to parse the username, password, hostname, port before.
Or, we have others.

Sincerely

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Contributor guide

Open the contributing guide

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.

Research direction

Start by reviewing urllib.parse._splitnetloc and the MySQL-style URL example in the issue. Determine the intended handling of # and ? in usernames or passwords within the netloc, then verify that the chosen behavior preserves the remaining URL delimiters and does not introduce parsing regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.