Re: Re: Struts 7: action class finder

Lukasz Lenart <[email protected]>
Newsgroups gmane.comp.jakarta.struts.devel
Message-ID <CAMopvkOG9_XSRWByc1GRp+ALG2-boNkJ456OusCh_Q2Xf_UKkQ@mail.gmail.com>
czw., 19 gru 2024 o 21:42 Florian Schlittgen <[email protected]> napisał(a):
>
> You're right, the package is supposed to be excluded. So I started
> debugging and tracked it down to the
> org.apache.struts2.util.WildcardHelper. There seems to be an issue, as
> you can see in this example:
>
>      public static void main(String[] args) {
>          String packageExclude = "org.apache.struts2.*";
>          String classPackageName = "org.apache.struts2";
>
>          WildcardHelper wildcardHelper = new WildcardHelper();
>          int[] packagePattern =
> wildcardHelper.compilePattern(packageExclude);
>          System.out.println(wildcardHelper.match(new HashMap<>(),
> classPackageName, packagePattern));
>      }
>
> The output is 'false', so the pattern "org.apache.struts2.*" does not
> match with the package "org.apache.struts2".
> Maybe you'll know immediately what the problem is. Otherwise, I can take
> another look and find the error in the match method... just let me know.

It doesn't match because there is no ".", this works:

public static void main(String[] args) {
    String packageExclude = "org.apache.struts2.*";
    String classPackageName = "org.apache.struts2.";

    WildcardHelper wildcardHelper = new WildcardHelper();
    int[] packagePattern =
            wildcardHelper.compilePattern(packageExclude);
    System.out.println(wildcardHelper.match(new HashMap<>(),
            classPackageName, packagePattern));
}

also this works

public void testMatchStrutsPackages() {
    // given
    HashMap<String, String> matchedPatterns = new HashMap<>();
    int[] pattern = wildcardHelper.compilePattern("org.apache.struts2.*");

    // when & then
    assertTrue(wildcardHelper.match(matchedPatterns,
"org.apache.struts2.XWorkTestCase", pattern));
    assertEquals("org.apache.struts2.XWorkTestCase", matchedPatterns.get("0"));
    assertEquals("XWorkTestCase", matchedPatterns.get("1"));

    assertTrue(wildcardHelper.match(matchedPatterns,
"org.apache.struts2.core.SomeClass", pattern));
    assertEquals("org.apache.struts2.core.SomeClass", matchedPatterns.get("0"));
    assertEquals("core.SomeClass", matchedPatterns.get("1"));
}

It must be something else


Cheers
Lukasz
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.