Skip to content

[Bug] Hyperlink with a # part is read back without its target #1138

Description

@nkuprins

Search before asking

  • I searched in the issues and found nothing similar.

Fesod version

main

JDK version

any

Operating system

Linux

Steps To Reproduce

Open an .xlsx whose cell A1 links to an external URL that has a fragment,
e.g. https://example.com/page#section.

<!-- xl/worksheets/sheet1.xml -->
<hyperlink ref="A1" r:id="rId1" location="section" display="frag"/>
<hyperlink ref="A2" r:id="rId2" display="plain"/>

<!-- xl/worksheets/_rels/sheet1.xml.rels -->
<Relationship Id="rId1" Target="https://example.com/page" TargetMode="External" Type=".../hyperlink"/>
<Relationship Id="rId2" Target="https://example.com/plain" TargetMode="External" Type=".../hyperlink"/>

extraHyperlinkFragment.xlsx

Current Behavior

[section, https://example.com/plain]

The fragment is reported as if it were a link inside the workbook, and the URL https://example.com/page is lost.

The same happens to a link to a cell in another workbook, other.xlsx#Sheet1!A1, which is stored the same way:

<hyperlink ref="A1" r:id="rId1" location="Sheet1!A1"/>
<Relationship Id="rId1" Target="other.xlsx" TargetMode="External" Type=".../hyperlink"/>

It is read back as Sheet1!A1, which looks like a link to a cell in the workbook being read.

Expected Behavior

[https://example.com/page#section, https://example.com/plain]

and other.xlsx#Sheet1!A1 for the other-workbook link. This is what POI returns for the same files (XSSFHyperlink.getAddress()).

Anything else?

HyperlinkTagHandler.startElement treats location and r:id as either/or: when location is present it reports it and returns before resolving r:id. That is right for links inside the workbook, which only carry location, but an external link with a # part carries both.

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions