lib_mysqludf_pregFS#10: preg_replace(pattern, replacement, str) returns empty string when replacement is NULL

This is the official MySQL UDF Repository bug tracker. Please use it with care.

  • Before submitting a new bug report, please make sure the bug is not already reported.
  • Include the given error code, trace and any other debugging information supplied.
  • Please leave your e-mail address, so we can get back to you if it is unclear how to reproduce the bug.

Thank you!

| Tasklist |

FS#10 - preg_replace(pattern, replacement, str) returns empty string when replacement is NULL

Attached to Project: lib_mysqludf_preg
Opened by 'vitspec-gmail' - Friday, 23 January 2009, 16:57 GMT+2
Task Type Bug Report
Category Backend / Core
Status Assigned
Assigned To Rich Waters (rich)
Operating System FreeBSD
Severity Medium
Priority Normal
Reported Version 1.0
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No

Details

preg_replace(pattern, replacement, str) returns empty string when replacement is NULL
mysql-5.1.22
This task depends upon

Comment by 'raw-goodhumans' - Sunday, 22 November 2009, 15:34 GMT+2
It's unclear what is expected behavior here. Should the library issue an error or should it just return the subject passed in.
Comment by 'raw-goodhumans' - Sunday, 22 November 2009, 16:36 GMT+2
Looks like the library is acting appropriately. It issues an error message to stderr and sets *error=1 in the main function. Handling
this as an error condition matches php's handling of the empty-string as an error condition.

One minor improvement could be to recognize a NULL that is passed in as a constant argument and error in the init function
where a message can be passed back to the user.
Comment by Rich Waters (rich) - Tuesday, 24 November 2009, 00:29 GMT+2
Looks like I read this one incorrectly when I made the last comments. Those last comments referred to NULL patterns. It looks
like this bug is for NULL replacements.
Comment by Rich Waters (rich) - Tuesday, 24 November 2009, 01:36 GMT+2
I'm not sure what the desired behavior here is. There are a few different things that can be done if a NULL is passed in for the replacement. Choice 1 is to
error. I don't think this is a great choice because of the limited error handling capabilities of the mysql udf api. Choice 2 is to return the subject unchanged.
This might be the most appropriate choice but I'm not sure its what is expected, and there is a reasonable workaround which is to filter out the NULLs before calling preg_replace. Choice 3 is what currently occurs which is that the portion of the regex
that matches the pattern is removed (ie. replaced with an empty string). I'll leave this bug open in case anyone wants to suggest some better
approaches or provide some specific examples of what should occur.
Add comment
Captcha image - if you can't read the image please send an e-mail Please enter the code displayed in the image. The verification is case-insensitive.

Loading...