From 332f8896f75522f08bf9433720637ddf601d2724 Mon Sep 17 00:00:00 2001 From: safa Date: Mon, 2 Nov 2026 22:25:40 +0530 Subject: [PATCH] avoid quadratic trailing-char search in _extract_possible_number --- python/phonenumbers/phonenumberutil.py | 5 ++++- python/tests/shortnumberinfotest.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/python/phonenumbers/phonenumberutil.py b/python/phonenumbers/phonenumberutil.py index 0fc3f5986..f40f5ccb2 100644 --- a/python/phonenumbers/phonenumberutil.py +++ b/python/phonenumbers/phonenumberutil.py @@ -248,7 +248,10 @@ # which nets down to: >=1 non-Number, non-Letter, non-# characters at string end # In Python Unicode regexp mode '(?u)', the class '[^#\w]' will match anything # that is not # and is not alphanumeric and is not underscore. -_UNWANTED_END_CHARS = u(r"(?u)(?:_|[^#\w])+$") +# The negative lookbehind only lets a match start at the beginning of a run +# of these characters; without it, search() retries from every position in a +# run that is not at the end of the string, which is quadratic in its length. +_UNWANTED_END_CHARS = u(r"(?u)(?