Skip to content

2.7 1485 reference parsing issues#1507

Open
thboileau wants to merge 3 commits into
2.7from
2.7_1485_reference_parsing_issues
Open

2.7 1485 reference parsing issues#1507
thboileau wants to merge 3 commits into
2.7from
2.7_1485_reference_parsing_issues

Conversation

@thboileau
Copy link
Copy Markdown
Contributor

The aim

Fix parsing of Reference instances as reported in ticket 1485

Check-list

  • PR size
    • Under 300 lines ✅
    • Can't be split without complicating the process even more
  • Tests
    • Added
    • Not applicable (why?)
  • Doc
    • Added
    • Not applicable
  • Reviewer
    • Asked for a review
    • Added label DO NOT REVIEW

@thboileau thboileau force-pushed the 2.7_1485_reference_parsing_issues branch from 5f2d97b to 23412fe Compare May 15, 2026 20:05
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ReferenceTestCase with 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;
}
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

Successfully merging this pull request may close these issues.

2 participants