Skip to content

Commit

Permalink
Merge pull request #1 from Papyxulo/Papyxulo-patch-1
Browse files Browse the repository at this point in the history
Fix for the pwndoc-ng#399 (broken url reference links)
  • Loading branch information
Papyxulo authored Aug 22, 2024
2 parents a8a5a4e + fb3341f commit b7e8682
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions backend/src/lib/report-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,24 @@ expressions.filters.lines = function(input) {

// Creates a hyperlink: {@input | linkTo: 'https://example.com' | p}
expressions.filters.linkTo = function(input, url) {
var encodedUrl = encodeURIComponent(url); // fix breaking word with special characters in reference
var encodedInput = encodeURIComponent(input); // fix breaking word with special characters in reference
return `<w:r><w:fldChar w:fldCharType="begin"/></w:r>
<w:r><w:instrText xml:space="preserve"> HYPERLINK "${encodedUrl}" </w:instrText></w:r>
<w:r><w:fldChar w:fldCharType="separate"/></w:r>
<w:r><w:rPr><w:rStyle w:val="Hyperlink"/></w:rPr>
<w:t>${encodedInput}</w:t>
</w:r><w:r><w:fldChar w:fldCharType="end"/></w:r>`;

// fix breaking word with special characters in reference
var entityencodedurl = url.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); // encode to prevent xml issues
var entityencodedinput = input.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); // encode to prevent xml issues
var encodedUrl = encodeURI(entityencodedurl); // encode the uri
var encodedInput = encodeURI(entityencodedinput); // encode the uri

return `<w:r>
<w:fldChar w:fldCharType="begin"/></w:r><w:r>
<w:instrText xml:space="preserve"> HYPERLINK "${encodedUrl}" </w:instrText>
</w:r><w:r><w:fldChar w:fldCharType="separate"/></w:r>
<w:r><w:rPr><w:rStyle w:val="Hyperlink"/>
<w:shd w:val="clear" w:color="auto" w:fill="auto"/> <!-- Remove any shading -->
<w:u w:val="single"/> <!-- Add underline -->
<w:color w:val="0000FF"/> <!-- Set text color to blue -->
</w:rPr><w:t>${encodedInput}</w:t></w:r><w:r><w:fldChar w:fldCharType="end"/>
</w:r>`;

}

// Loop over the input object, providing acccess to its keys and values: {#findings | loopObject}{key}{value.title}{/findings | loopObject}
Expand Down

0 comments on commit b7e8682

Please sign in to comment.