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

Support \Q\E quotation #22

Closed
vkopichenko opened this issue Mar 14, 2016 · 3 comments
Closed

Support \Q\E quotation #22

vkopichenko opened this issue Mar 14, 2016 · 3 comments

Comments

@vkopichenko
Copy link

vkopichenko commented Mar 14, 2016

It would be nice to provide possiblity to escape some parts of regex from generation without need to escape each special character one by one.
For example I'd like to use

minion_\d{3}\Q@gru.evil\E

instead of

minion_\d{3}\@gru\.evil

Here is a workaround code to transform the former to latter:

    private static String requote(String regex) {
        final Pattern PATTERN_QUOTED = Pattern.compile("\\\\Q(.*?)\\\\E");
        // http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions
        // adding "@" prevents StackOverflowError inside generex: https://github.com/mifmif/Generex/issues/21
        final Pattern PATTERN_SPECIALS = Pattern.compile("[.^$*+?(){|\\[\\\\@]");
        StringBuilder sb = new StringBuilder(regex);
        Matcher matcher = PATTERN_QUOTED.matcher(sb);
        while (matcher.find()) {
            sb.replace(matcher.start(), matcher.end(), PATTERN_SPECIALS.matcher(matcher.group(1)).replaceAll("\\\\$0"));
            //matcher.reset();
        }
        return sb.toString();
    }
@mifmif
Copy link
Owner

mifmif commented Mar 15, 2016

It's a nice feature, I will work on this point, you can fork the project and add this feature, then i will merge your request.

mifmif added a commit that referenced this issue May 3, 2016
pseudo random suite many times (issue #23)
Add support to \Q \E requote notation to interpret meta-char between  \Q
and \E as simple chars (issue #22)
@mifmif
Copy link
Owner

mifmif commented May 3, 2016

This feature is now supported

@mifmif mifmif closed this as completed May 3, 2016
vkopichenko added a commit to vkopichenko/Generex that referenced this issue Jul 2, 2019
* escape @&"<#~ automaton special chars
* proper handling of multiple adjacent quote groups
* support for multiline patterns
* compiled regex caching
* exhaustive test case for everything above
vkopichenko added a commit to vkopichenko/Generex that referenced this issue Jul 2, 2019


[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.

Initially Java level was missing in pom that caused problems when importing project into IntelliJ IDEA.
I've checked that https://repo1.maven.org/maven2/com/github/mifmif/generex/1.0.2/generex-1.0.2.jar was built with Java 5 and added this explicitly into pom.
Now have to revert this to make CI build to pass.

Would happily use Java 8 features in the fix and the test, BTW.
vkopichenko added a commit to vkopichenko/Generex that referenced this issue Jul 2, 2019
…553247272

[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.

Have to bump java version to 6.
Bump further right to 8 may be considered too.
vkopichenko added a commit to vkopichenko/Generex that referenced this issue Jul 2, 2019
…553253525

[ERROR] Failed to execute goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument (verification) on project generex: Execution verification of goal org.codehaus.mojo:cobertura-maven-plugin:2.6:instrument failed: Plugin org.codehaus.mojo:cobertura-maven-plugin:2.6 or one of its dependencies could not be resolved: Could not find artifact com.sun:tools:jar:0 at specified path /usr/local/lib/jvm/openjdk11/../lib/tools.jar

Had to switch from cobertura to jacoco due to mojohaus/cobertura-maven-plugin#30 still not resolved.

Plus minor build and javadoc improvements.
vkopichenko added a commit to vkopichenko/Generex that referenced this issue Jul 2, 2019
…553275106

[ERROR] Failed to execute goal org.codehaus.mojo:findbugs-maven-plugin:3.0.3:findbugs (findbugs) on project generex: Unable to parse configuration of mojo org.codehaus.mojo:findbugs-maven-plugin:3.0.3:findbugs for parameter pluginArtifacts: Cannot assign configuration entry 'pluginArtifacts' with value '${plugin.artifacts}' of type java.util.Collections.UnmodifiableRandomAccessList to property of type java.util.ArrayList

Updating findbugs version per https://stackoverflow.com/questions/53676071/maven-clean-command-java-util-collections-unmodifiablerandomaccesslist-to-prope.
@vkopichenko
Copy link
Author

vkopichenko commented Jul 2, 2019

The initial requote implementation here were vulnerable to some problems:

  • no escape for &"<#~ automaton special chars
  • incorrect handling of multiple adjacent quote groups
  • no support for multiline patterns

These were fixed in PR #48.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants