Skip to content

fix(1485) Reference parsing issues#1486

Open
thboileau wants to merge 1 commit into2.6from
1485_reference_parsing_issues
Open

fix(1485) Reference parsing issues#1486
thboileau wants to merge 1 commit into2.6from
1485_reference_parsing_issues

Conversation

@thboileau
Copy link
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 1485_reference_parsing_issues branch 2 times, most recently from 9b06b9e to 1a66044 Compare February 22, 2026 21:46
newPart = newAuthority;
} else if (oldPart.startsWith("//")) {
int index = oldPart.indexOf('/', 2);
int indexSlash = oldPart.indexOf('/', 2);
Copy link
Contributor Author

@thboileau thboileau Feb 22, 2026

Choose a reason for hiding this comment

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

we have to take care of the case where the "/" comes from the query string (because of the call to getSchemeSpecificPart()).

// Existing fragment
if (fragment != null) {
this.internalRef = this.internalRef.substring(0, this.fragmentIndex + 1) + fragment;
setInternalRef(this.internalRef.substring(0, this.fragmentIndex + 1) + fragment);
Copy link
Contributor Author

@thboileau thboileau Feb 22, 2026

Choose a reason for hiding this comment

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

Intellij complains when this.internalRef is set with a value computed thanks to itself, because it's a volatile class member. It leads to use a setter.

// Path found
final int index2 = oldPart.indexOf('?');
final int indexSlash = oldPart.indexOf('/', 2);
final int indexQuery = oldPart.indexOf('?', 2);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have to take care of the case where the "/" comes from the query string (because of the call to getSchemeSpecificPart()).

import org.restlet.engine.header.HeaderConstants;
import org.restlet.engine.util.ReferenceUtils;
import org.restlet.util.Series;
import static org.junit.jupiter.api.Assertions.assertEquals;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The class has been reworked to make it shorter using Junit parameterized tests

"http://localhost/abc?query#fragment,/def",
"http://localhost/abc#fragment?query,/def",
"http://localhost#fragment/abc?query,/def",
"http://localhost?query/abc,/def"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this case was failing (case where '/' is inside the query)

Reference originalRef = ReferenceUtils.getOriginalRef(ref, headers);
assertEquals(originalRef.getSchemeProtocol(), Protocol.HTTPS);
assertEquals(originalRef.getHostPort(), 123);
assertEquals(Protocol.HTTPS, originalRef.getSchemeProtocol());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

switch the expected value in first position.

assertEquals("/foo/", parentRef.toString());
}

/**
Copy link
Contributor Author

@thboileau thboileau Feb 22, 2026

Choose a reason for hiding this comment

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

this part has especially been reworked to make it shorter

"http://host.com/dir/sub", "http://host.com/dir/sub",
"http://host.com/dir/sub", null, null);
@Nested
class TestParsing {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

isolate "parsing" test cases (nice presentation in Intellij)

"http://www.gamasutra.com/view/feature/177267/devil_may_cry_born_again.php"),
ref).getTargetRef();
assertEquals(
"http://twitter.com?status=RT%20@gamasutra:%20%20Devil%20May%20Cry%20:%20Born%20Again%20http:?status=RT%20@gamasutra:%20%20Devil%20May%20Cry%20:%20Born%20Again%20http://www.gamasutra.com/view/feature/177267/",
Copy link
Contributor Author

@thboileau thboileau Feb 22, 2026

Choose a reason for hiding this comment

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

The previous test was wrong.
It showed this log

Can't parse hostPort : [hostRef,requestUri]=[null,http://twitter.com?status=RT%20@gamasutra:%20%20Devil%20May%20Cry%20:%20Born%20Again%20http:?status=RT%20@gamasutra:%20%20Devil%20May%20Cry%20:%20Born%20Again%20http://www.gamasutra.com/view/feature/177267/]

index = part.indexOf('?');
if (index != -1) {
return part.substring(2, index);
// At this point, no fragment, but a query string may come from
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have to take care of the case where the '/' is inside the query

@thboileau thboileau force-pushed the 1485_reference_parsing_issues branch from b45080f to b8f3258 Compare February 22, 2026 22:19
@thboileau thboileau requested a review from jlouvel February 22, 2026 22:28
"http://localhost/?query,http,localhost,/,query,",
"http://localhost/#?query,http,localhost,/,,?query",
"http://localhost/path#frag/ment,http,localhost,/path,,frag/ment",
"http://localhost/path?qu/ery,http,localhost,/path,qu/ery,"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This case was failing ('/' inside query)

assertEquals("http://localhost:1234/test/last", ref.toString());
}


Copy link
Contributor Author

Choose a reason for hiding this comment

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

new tests

ref = new Reference(uri);
assertEquals("file:///C%7C/wherever%5Cwhatever.swf", ref.toString());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

new tests

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.regex.Pattern;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

formatting implies order of "imports" as well... we will take care of that later

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.

1 participant