|
[
Permalink
| « Hide
]
Andreas Sahlbach added a comment - 04/Jan/07 02:19 PM
hmm...some of my examples above are messed up, because Jira replaces my double-backslashes with newlines. So here they come again:
I just found this issue because of a report by a user discovering the unexpected regex behavior of minus(String, Object).
I object to making a breaking change to the behavior of this (or any) public API at a bug fix release level (like 1.5.2). At a minimum this type of change must wait until a minor release like 1.6. But I'm not sure I'd agree with this change at all. I do agree that this behavior is at first a surprise, but I suspect the original implementor intended this and it is consistent with Groovy's support of regex. Certainly it has been this way since 1.0 and is documented (although the "see also" makes the assumption that the reader is a Java expert or will click the link). I do believe the documentation should be updated to make the current behavior clearer. And if it were to change in the future, then the release notes are going to need to make a big notice about this breaking change. And lastly, if you're gonna yank the regex behavior, don't use String.replaceFirst at all since it is the worst possible performance (quote a regex pattern, compile the pattern, then do regex replacement)! If you want to string literal replacement you use String.indexOf(String). In Groovy 1.0, the Javadoc made no mention of the regex-style handling under the covers for the DGM#minus(String, Object) method (nor did GinA as far as I can find). In 1.5.0 and 1.5.1, the Javadoc is not very clear but mentions this regex behavior. We should clarify this doco in 1.5.2 if we can. The proposed behavior for 1.6.0 is that if the remove target is a pattern, regex-like behavior will occur. If target is not a pattern, the text will simply be literally removed from the String. This results in the following behavior:
assert 'abcda.ce' - /a.c/ == 'abcde' assert 'abcda.ce' - ~/a.c/ == 'da.ce' Leaving this issue to cover just the 1.5.2 case, the 1.6 case is now covered in a subtask.
Just to summarize options at this stage:
Browsing those patches, I found that RegexUtils.quote seems to have an incorrect behavior in some cases.
System.out.println(RegexUtils.quote("\\")); // ouputs \Q\\E System.out.println(RegexUtils.quote("\\\\E")); // outputs \Q\\E\\E\Q\E Those are the same results as Pattern.quote:
monospaced assert Pattern.quote(' println Pattern.quote(' And speaking of RegexUtils it also needs to implement quoteReplacement for Matcher.quoteReplacement. But I guess that's for another JIRA... You're right, forget my comment.
Should be fixed after the merge of trunk into the branch.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||