Skip to content

A re.error occurs when a proxy is used to access an IPv6 address in the Windows operating system. #103239

@llchry

Description

@llchry

Bug report

Prerequisites

  1. Windows operating system
  2. A proxy server is used.
  3. The trustlist of the proxy service contains '[*'.

Use the following code to request an IPv6 address such as https://[fa::01]:80/,the following error occurs:
re.error: unterminated character set at position 0

req = request.Request(url=url, method=method, headers=headers, data=data)
resp = request.urlopen(req, timeout=timeout, context=ctx)

I noticed that the problem comes from the proxy_bypass_registry method in urllib/request.py, which reads the system's proxy configuration and checks whether the host needs a proxy, but the regular expression [* works fine on windows, but fails to verify in python. I thought about configuring *] on windows, but this won't save, so I'm guessing there's a difference in the regular expression implementation between the two systems.
So can we add an escape processing in the code and replace [ with \[?

Your environment

  • CPython versions tested on: Python 3.9.13
  • Operating system and architecture: Windows 10

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-windowsstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions