Skip to content

Commit

Permalink
Add test for preserving (and not adding additional) URL encoding
Browse files Browse the repository at this point in the history
Make Sink.link(...) javadoc more HTML agnostic by just referencing the
URI RFC
  • Loading branch information
kwin committed Oct 8, 2023
1 parent a1e97f9 commit 608ebb1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,28 @@ public void testFigure() throws Exception {
assertEquals("figure_", it.next().getName());
}

@Test
public void testLink() throws Exception {
// param1 value = "/&ü" URL encoded twice!
String text = "<div>"
+ "<a href=\"http://www.fo.com/index.html&amp;param1=%252F%2526%25C3%25BC\"></a>"
+ "</div>";

parser.parse(text, sink);
Iterator<SinkEventElement> it = sink.getEventList().iterator();

SinkEventElement element = it.next();
assertEquals("division", element.getName());

element = it.next();
assertEquals("link", element.getName());
assertEquals("http://www.fo.com/index.html&param1=%252F%2526%25C3%25BC", element.getArgs()[0]);
assertEquals("link_", it.next().getName());

element = it.next();
assertEquals("division_", element.getName());
}

@Test
public void testAnchorLink() throws Exception {
String text = "<div><a href=\"\"></a>" + "<a href=\"valid\"></a>"
Expand Down Expand Up @@ -748,7 +770,6 @@ public void testAnchorLink() throws Exception {
element = it.next();
assertEquals("division_", element.getName());
}

/**
* Test entities in attributes.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1433,9 +1433,11 @@ public interface Sink extends AutoCloseable {
* Starts a link.
*
* <p>
* The <code>name</code> parameter has to be a valid html <code>href</code>
* parameter, ie for internal links (links to an anchor within the same source
* The <code>name</code> parameter has to be a valid URI according to
* <a href="https://datatracker.ietf.org/doc/html/rfc3986">RFC 3986</a>,
* i.e. for internal links (links to an anchor within the same source
* document), <code>name</code> should start with the character "#".
* This also implies that all unsafe characters are already encoded.
* </p>
* <p>
* Supported attributes are the {@link SinkEventAttributes base attributes} plus:
Expand All @@ -1455,6 +1457,7 @@ public interface Sink extends AutoCloseable {
* @param name the name of the link.
* @param attributes A set of {@link SinkEventAttributes}, may be <code>null</code>.
* @since 1.1
* @see java.net.URI#toASCIIString()
*/
void link(String name, SinkEventAttributes attributes);

Expand Down

0 comments on commit 608ebb1

Please sign in to comment.