html-to-docx
html-to-docx copied to clipboard
Safari : Invalid regular expression: invalid group specifier name (image-to-base64)
I finally integrated well this library to my React app but trying it in Safari show me a blank page and there is this error in Safari's console :
Like this SO response tells Safari doesn't support lookbehind (that is, the (?<=/)).
I finally found which dependency has the breaking regex and it is image-to-base64, which is now archived since Nov 9, 2022, and you added it to html-to-docx
in this commit.
Second, the isValidUrl
helper function from the src/utils/url.js
is using the same lookbehind feature, breaking Safari.
I found this fork which has fixed the issue, with an npm package published, not sure if it can be used.
@privateOmega do you have an input on this issue please ?
@privateOmega I'm interested in hearing your take on this too.
@zedtux Lookbehind in regex seems to finally be on it's way to get implemented in Safari: WebKit bug report, PR
@zedtux Sorry for the delay in getting to this issue so late.
@tasola Thanks for the notification message.
Since this isnt something that really breaks the usage for a majority of users, I am not sure if we should undertake the effort to fix this.
Also I am super bad at regex and would appreciate if one of you could validate if the changes made in the fork is good, I will take your word for it, and I can either raise a PR to use the fork or can merge if either of you raise it.
@privateOmega Fair. I don't think it's a minor problem that the usage of this package doesn't work on one of the major browsers though... However I agree that it's probably not worth undertaking the effort (at least not for me), seeing how it might get fixed once Safari releases the PR linked above.
I just want to add: Good job developing this project, Kiran (and contributors)!
I am using this package and I downgraded to 1.4.0 (npm install [email protected]
) and it at least gets Safari to load and I was able to create a docx file.
I haven't tested full functionality, but for now downgrading seemed to help.
@bryaneaton13 Thanks, it seems to work good for me too. And I can't notice any difference in functionality as far as my use case goes. @privateOmega, do you know any risks with running 1.4.0
right off the bat?
Yeah ok I found one; https://github.com/privateOmega/html-to-docx/issues/41 seems to be happening to me when running 1.4.0
unfortunately...
I ended up using 1.4.0
, but iterating through each image and replace it with its wrapping <p>
using :
const parentNode = images[i].parentNode as HTMLElement | undefined
parentNode?.replaceWith(images[i])
Far from optimal of course, but I'm very limited on time at the moment.
I'm using patch-package in my project which allows me to patches node_modules/
libraries.
I used it to patch this lib in order to "fix" the regex breaking Safari. Would you like me to share it with you @privateOmega ?
@tasola @zedtux Yes going back to 1.4.0 will render you without many functionalities and fixes like nested images, cannot use url in image src etc.
Fixed the issue in a fork if anyone is interested: https://github.com/corwinstephen/fixed-html-to-docx
Two bad regexes, one in image-to-base64 and the other in utils/url.js
. This switches to the fixed base64 package mentioned above and swaps the URL regex out for a different one.
@privateOmega is there a fix for the regex in prospect? Same problem for me here.