-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[MNG-5862] Support XML entities and XInclude #1205
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fcc2c9f
[MNG-5862] Support XML entities and XInclude
gnodet 3fffae9
Fixes after review
gnodet a3f2bd6
Switch off external entities and xinclude by default (opt-in)
gnodet 84e4e03
Fix variable names in LocalXmlResolver
gnodet 0679917
Fixes
gnodet 5629c20
Fix UT
gnodet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
maven-model-builder/src/main/java/org/apache/maven/model/io/LocalXmlResolver.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.maven.model.io; | ||
|
|
||
| import javax.xml.stream.XMLResolver; | ||
| import javax.xml.stream.XMLStreamException; | ||
| import javax.xml.transform.stream.StreamSource; | ||
|
|
||
| import java.io.IOException; | ||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
|
|
||
| public class LocalXmlResolver implements XMLResolver { | ||
|
|
||
| private final Path rootDirectory; | ||
|
|
||
| public LocalXmlResolver(Path rootDirectory) { | ||
| this.rootDirectory = rootDirectory != null ? rootDirectory.normalize() : null; | ||
| } | ||
|
|
||
| @Override | ||
| public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) | ||
| throws XMLStreamException { | ||
| if (rootDirectory == null) { | ||
| return null; | ||
| } | ||
| if (systemID == null) { | ||
| throw new XMLStreamException("systemID is null"); | ||
| } | ||
| if (baseURI == null) { | ||
| throw new XMLStreamException("baseURI is null"); | ||
| } | ||
| URI baseUri; | ||
| try { | ||
| baseUri = new URI(baseURI).normalize(); | ||
| } catch (URISyntaxException e) { | ||
| throw new XMLStreamException("Invalid syntax for baseURI URI: " + baseURI, e); | ||
| } | ||
| URI systemIDUri; | ||
| try { | ||
| systemIDUri = new URI(systemID).normalize(); | ||
| } catch (URISyntaxException e) { | ||
| throw new XMLStreamException("Invalid syntax for systemID URI: " + systemID, e); | ||
| } | ||
| if (systemIDUri.getScheme() != null) { | ||
| throw new XMLStreamException("systemID must be a relative URI: " + systemID); | ||
| } | ||
| Path base = Paths.get(baseUri).normalize(); | ||
| if (!base.startsWith(rootDirectory)) { | ||
| return null; | ||
| } | ||
| Path systemIDPath = Paths.get(systemIDUri.getSchemeSpecificPart()).normalize(); | ||
| if (systemIDPath.isAbsolute()) { | ||
| throw new XMLStreamException("systemID must be a relative path: " + systemID); | ||
| } | ||
| Path resourcePath = base.resolveSibling(systemIDPath).normalize(); | ||
| if (!resourcePath.startsWith(rootDirectory)) { | ||
| throw new XMLStreamException("systemID cannot refer to a path outside rootDirectory: " + systemID); | ||
| } | ||
| try { | ||
| return new StreamSource( | ||
| Files.newInputStream(resourcePath), resourcePath.toUri().toASCIIString()); | ||
| } catch (IOException e) { | ||
| throw new XMLStreamException("Unable to create Source for " + systemID + ": " + e.getMessage(), e); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.