CMS MADE SIMPLE FORGE

PDF Generator

 

[#12273] Links are incorrect in output

avatar
Created By: Jaap Grol (jagro)
Date Submitted: Sun Mar 15 10:18:13 -0400 2020

Assigned To:
Version: 1.0
CMSMS Version: 2.2.13
Severity: Major
Resolution: None
State: Open
Summary:
Links are incorrect in output
Detailed Description:
When a page contains links, these are preceded by the site-URL.
Two different situations: link to external page & mailto-link are both adjusted.
https://www.afas.nl/?utm_source=hrtechreview&utm_medium=page becomes
https://devel.hrtechreview.nl/https://www.afas.nl/?utm_source=hrtechreview&utm_medium=page
https://www.purplehrm.com/ becomes
https://devel.hrtechreview.nl/https://www.purplehrm.com/
vragen@hrtechreview.nl becomes
https://devel.hrtechreview.nl/mailto:vragen@hrtechreview.nl

Static page to test/show this issue: https://devel.hrtechreview.nl/pdftest

How can we prevent this from happening? 


History

Comments
avatar
Date: 2020-03-21 03:50
Posted By: Jaap Grol (jagro)

I already tried removing the base-tag from the template, but that didn't help.
      
avatar
Date: 2021-03-07 16:14
Posted By: Friedrich Kammer (frie)

This also causes failing in accessing images, where the root_url or uploads_url
ist used in the src attribute. Same problem for images referenced in css.
      
avatar
Date: 2021-03-13 12:36
Posted By: Friedrich Kammer (frie)

Seems that there are a couple of bugs in the code (PDFGenerator.module.php):

1. Function Relative2Absolute

For a couple of tag attributes (img/src, a/href ...) the code checks for 
  strpos($src, $prefix) !== 0 && $this->isAbsolute($src)
and prefixes the link with $prefix, if true. This makes no sense at all for
links which already are absolute.
For relative links strpos returns FALSE, so comparison against 0 finally gives
the correct result (just by chance).
$this->isAbsolute($src) == FALSE  and  ( strpos($src, $prefix) == FALSE  or 
strpos($src, $prefix) > 0 )
gives correct behaviour, but $src containing $prefix ({root_url}) somewhere
behind also makes no sense, so the last check can also be dropped.

2. Function function GetContentURL

https vs. http is checked as
$protocol = stripos($_SERVER['SERVER_PROTOCOL'], 'https') === true ?
'https://' : 'http://';

SERVER_PROTOCOL does not tell wether http or https applies, so the url always is
formed with http.
Correct solution:
  $protocol = ( empty($_SERVER['HTTPS']) ? 'http://' : 'https://' );

For that reason the module does not work at all for https-based sites
      
Updates

Updated: 2020-03-21 03:50
resolution_id: => 5