Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CompileRegex not actually setting a valid error code. #775

Merged
merged 2 commits into from May 28, 2018

Conversation

@Drifter321
Copy link
Member

Drifter321 commented Feb 27, 2018

CompileRegex is currently setting the error code to the offset of where the error occurred rather than the actual error.

To fix this pcre_compile was replaced with pcre_compile2 and a map used to convert the pcre error to a simpler (posix) error code but maintaining pcre's error string and adding the error codes to the enum. Also changed the internal member names since it was rather confusing. In the future we can also add in the offset so we can pass the offset where the error occurred.

The reason for mapping the errors is that pcre's error codes dont seem to be documented at all(?) From pcre_internal.h the errors are named ERR0, ERR1 etc... and i couldn't find any more information. There is also over 80 of them (due to the amount of detail) so I think the posix error codes are a simpler approach.

Small test plugin and its output.

public void OnPluginStart()
{
	char test_string[] = "my9_test1+string2.wooooo5";
	
	RegexError errorcode;
	char error[128]

	Regex re = new Regex("([^_|\\\\][a-zA-z|+])([0-9]", _, error, sizeof(error), errorcode);
	
	PrintToServer("Error code is %i (%s)", view_as<int>(errorcode), error);
}

Error code is 11 (missing ))
@404UNFca

This comment has been minimized.

Copy link
Contributor

404UNFca commented Feb 28, 2018

So this was actually a bug then? Glad to see it's gonna be fixed.

@Drifter321 Drifter321 merged commit d430bd2 into master May 28, 2018
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Headline Headline deleted the regex-compile-fix branch Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.