2.7 1485 reference parsing issues#1507
Open
thboileau wants to merge 3 commits into
Open
Conversation
5f2d97b to
23412fe
Compare
|
There was a problem hiding this comment.
Pull request overview
This PR addresses Restlet issue #1485 by tightening Reference parsing/validation so malformed schemes and authorities (notably around IPv6 and userinfo/host ambiguity) are detected earlier, and by expanding test coverage for these failure modes.
Changes:
- Add scheme and authority validation in
Reference(including IPv6 + embedded IPv4 tail checks) and adjust parsing around query/path boundary cases. - Extend
ReferenceTestCasewith new negative tests for malformed hosts/schemes and additional parsing edge cases. - Minor formatting/header updates in unrelated files.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
org.restlet/src/main/java/org/restlet/data/Reference.java |
Adds authority/scheme validation and adjusts parsing logic (query vs path; IPv6/IPv4-tail validation). |
org.restlet/src/test/java/org/restlet/data/ReferenceTestCase.java |
Adds/adjusts tests for invalid authorities/schemes and edge-case parsing behaviors. |
org.restlet/src/main/java/org/restlet/resource/ClientResource.java |
Updates copyright year. |
org.restlet.ext.freemarker/src/test/java/org/restlet/ext/freemarker/FreeMarkerTestCase.java |
Formatting-only change for Configuration initialization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+710
to
+724
| // Ensure that all characters are valid, otherwise encode them | ||
| for (int i = 0; valid && (i < uriRef.length()); i++) { | ||
| char character = uriRef.charAt(i); | ||
| if (!isValid(character)) { | ||
| valid = false; | ||
| Context.getCurrentLogger() | ||
| .log( | ||
| Level.FINE, | ||
| "Invalid character detected in URI reference at index \"{0}\": \"{1}\". It will be automatically encoded.", | ||
| new Object[] {i, character}); | ||
| } else if ((character == '%') && (i > uriRef.length() - 2)) { | ||
| // A percent encoding character has been detected but | ||
| // without the necessary two hexadecimal digits following | ||
| valid = false; | ||
| Context.getCurrentLogger() |
Comment on lines
+2964
to
+2971
| int doubleColonCount = countDoubleColons(ipV6); | ||
| if (doubleColonCount > 1) { | ||
| throw new IllegalArgumentException("Invalid IPv6 address format"); | ||
| } | ||
|
|
||
| String[] parts = ipV6.split(":", -1); | ||
| boolean hasIpV4Tail = parts[parts.length - 1].contains("."); | ||
|
|
Comment on lines
+3072
to
+3076
| if (scheme == null || scheme.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| if (!SCHEME_REGEXP.matcher(scheme).matches()) { |
Comment on lines
31
to
34
| protected static final String DEFAULT_SCHEME = "http"; | ||
|
|
||
| protected static final String DEFAULT_SCHEME_PART = "//"; | ||
| protected static final String DEFAULT_SCHEMEPART = "//"; | ||
|
|
Comment on lines
+3081
to
+3088
| /** | ||
| * Tackle non-atomic operation on volatile field 'internalRef'. | ||
| * | ||
| * @param internalRef The new value of field 'internalRef'. | ||
| */ | ||
| private void setInternalRef(final String internalRef) { | ||
| this.internalRef = internalRef; | ||
| } |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



The aim
Fix parsing of Reference instances as reported in ticket 1485
Check-list
DO NOT REVIEW