Skip to content

[string-strip-html] dumpLinkHrefsNearby with empty links causes output to contain the html partially #92

@edrichhans

Description

@edrichhans

Package's name
string-strip-html

Describe the bug
GIVEN I enable the option dumpLinkHrefsNearby
WHEN I pass an HTML with an empty href
THEN the output fails and returns the HTML partially

To Reproduce
Steps to reproduce the behavior:

Given the following test

const html = `
    <footer>
        <div>
            <div>
            <div><img src="assets/img/png/test.png" alt="" /></div>
            <div><span>Copyright 2022 test</span></div>
            <div>
                <a href=""><i aria-hidden="true"></i></a>
            </div>
            </div>
        </div>
    </footer>
`;

const { result } = stripHtml(html, {
    dumpLinkHrefsNearby: {
        enabled: true
    }
});
assert(result === 'Copyright 2022 test');

The output I am getting is:

  <footer>
                  <div>
                      <div>
                      <div><img src="assets/img/png/test.png" alt="" /></div>
                      <div><span>Copyright 2022 test</span></div>
                      <div>
                          <a href="

Expected behavior

Copyright 2022 test

Screenshots
N/A

Additional context
N/A

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions