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

Failed to scan resources when exits non ascii characters in resource path on SpringBootVFS #635

Closed
MisterChangRay opened this issue Mar 9, 2022 · 1 comment · Fixed by #675
Assignees
Labels
Milestone

Comments

@MisterChangRay
Copy link
Contributor

MisterChangRay commented Mar 9, 2022

in SpringBootVFS

  @Override
  protected List<String> list(URL url, String path) throws IOException {
    String urlString = url.toString();
    String baseUrlString = urlString.endsWith("/") ? urlString : urlString.concat("/");
    Resource[] resources = resourceResolver.getResources(baseUrlString + "**/*.class");
    return Stream.of(resources).map(resource -> preserveSubpackageName(baseUrlString, resource, path))
        .collect(Collectors.toList());
  }

  private static String preserveSubpackageName(final String baseUrlString, final Resource resource,
      final String rootPath) {
    try {
      return rootPath + (rootPath.endsWith("/") ? "" : "/")
          + resource.getURL().toString().substring(baseUrlString.length());
    } catch (IOException e) {
      throw new UncheckedIOException(e);
    }
  }

consider url may be containes none asccii charctor; such as chinese path.
the url.toString() return URLEncode result,
so the baseUrlString.length() should be grater than resource.getURL();

The bug exists in following code:

// if baseUrlString containes Space character, the baseUrlString.length() > resource.getURL().toString().length() is True 
// so there throw StringIndexOutOfBoundsException

 return rootPath + (rootPath.endsWith("/") ? "" : "/")
          + resource.getURL().toString().substring(baseUrlString.length());

微信截图_20220309143843

微信截图_20220309143922

微信截图_20220309154324

MisterChangRay added a commit to MisterChangRay/spring-boot-starter that referenced this issue Mar 9, 2022
@kazuki43zoo kazuki43zoo self-assigned this May 16, 2022
@kazuki43zoo kazuki43zoo added this to the 2.3.0 milestone May 16, 2022
kazuki43zoo pushed a commit to kazuki43zoo/spring-boot-starter that referenced this issue Jun 12, 2022
kazuki43zoo added a commit to kazuki43zoo/spring-boot-starter that referenced this issue Jun 12, 2022
kazuki43zoo added a commit to kazuki43zoo/spring-boot-starter that referenced this issue Jun 12, 2022
@kazuki43zoo kazuki43zoo changed the title org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.StringIndexOutOfBoundsException: String index out of range Failed to scan resources when exits non ascii characters in resource path on SpringBootVFS Jun 12, 2022
@kazuki43zoo
Copy link
Member

Hi @MisterChangRay , I've merged your pull request! Please try to use 2.3.0-SNAPSHOT.

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

Successfully merging a pull request may close this issue.

2 participants