<regex>: regex_search() throws regex_error(error_complexity) when a long string is used with a lookahead regex

Aperta
#6,347 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
cpp
Ambito
devtools

Direzione di ricerca

Inizia eseguendo il riproduttore da riga di comando C++ fornito con il percorso lungo e regex_search(), utilizzando l’ambiente MSVC 19.51 indicato. Traccia il modo in cui std::regex_search gestisce questo pattern e il risultato regex_error(error_complexity), quindi verifica che il riproduttore termini senza un’eccezione mantenendo il comportamento di corrispondenza previsto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug regex

Describe the bug

We a trying to upgrade the compiler to the latest MSVC version. First time we did hit this issue #5792. After it was fixed and new MSVC version published, we've upgraded again to 14.51 and now we are getting another issue, this time with regex_error(error_complexity) when a lookahead regex is being used with a really long search string.

Note that if I make the path string shorter, everything is working good. While this might be an expected limitation, we didn't have issues with Visual Studio 2022. Also on Linux with GCC 13 this code is working properly.

Command-line test case

#include <iostream>
#include <regex>

int main()
{
	try {
		std::regex pattern(R"((?:.+[\/\\])?(?:.+?)_(.+?)_(.+?)@(.+?)\.(?:exe|app))");
		std::smatch matches;
		std::string requestStringParams(R"(D:\some\really\long\path\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\dir\myapp.exe https://mysite.com/doaction/?action=56)");
		std::regex_search(requestStringParams, matches, pattern);
		std::cout << "no exception\n";
	}
	catch (const std::regex_error& ex) {
		std::cout << "regex_error with code " << ex.code() << "\n";
	}

	return 0;
}

This prints "regex_error with code 11".

Expected behavior

Should print "no exception".

STL version

Microsoft (R) C/C++ Optimizing Compiler Version 19.51.36248 for x64

Additional context

Might be related to issue #5792 but the exception is with different error code.

Lingua principale
C++
Stelle
11.2k
Fork
1.7k
Merge medio
4g 4h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/STL

Tutte le issue di microsoft/STL

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.