Button-Extension: Possible bug in _relToAbs in button.print.js using Chrome

Button-Extension: Possible bug in _relToAbs in button.print.js using Chrome

Aeon512Aeon512 Posts: 1Questions: 1Answers: 0

Hi,

I have noticed a problem with the Button extension of Datatables when using the print functionality in chrome.
Imho there might be small bug in the underlying javascript and i would like to contribute this information to this great project. If you find this information useful, feel free to incorporate it. If I'm totally wrong, just ignore it :-)

In button.print.js in Line 27 there is (_relToAbs)

// IE doesn't have a trailing slash on the host
if ( linkHost.indexOf('/') === -1 ) {
    linkHost += '/';
}

but when using Chrome these is some catch, since the linkHost does not have a training slash, but instead the trailing slash is added to the _link.pathname. In the consequence the print "View" gets CSS urls which look like http://www.example.org//path/to/style.css. Please notice the double slash after example.org.

For me it worked to change line 28 as follows

// IE doesn't have a trailing slash on the host, but Chrome has it on the pathname
if ( linkHost.indexOf('/') === -1 && _link.pathname.indexOf('/') != 0) {
    linkHost += '/';
}

Then everything works fine again.
Note, that when using nginx this problem is unnoticed, since nginx collapses by default double slashes.

All the best

Aeon512

Answers

  • allanallan Posts: 63,708Questions: 1Answers: 10,502 Site admin

    Sounds good to me - thanks for pointing that out and the fix!

    I've committed it here and it will be in the next release of Buttons.

    Regards,
    Allan

This discussion has been closed.