-
-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent app crash with malformed hrefs #432
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good.
In your jQuery variant, why on line 890 did you replace this.href
with href
?
I don't remember why we used this.href
, but it seems to me it was for a good reason (at least at that time), even if I don't remember the detail. So I find this change a bit risky. Apart from this, both methods (with or without jQuery) are fine for me.
I do not have the september wikimed for now, so could not test the code. But I trust you. If you'd like me to test anyway, I might do that later this week.
Don't bother downloading the September WikiMed, because I've now discovered the crash only occurs in Edge and in UWP (and apologies for not having tested more widely before -- I was more preoccupied with fixing it). Firefox and Chromium don't have a problem with the malformed URL, even though it doesn't yield a valid URL. I think it's still worth doing the jQuery solution, because it's generic. However, I need to find out at what point we changed to My suspicion is that we started to rewrite some of these functions without jQuery when we got the problem with #361 . For a short while, we started substituting pure JS in these routines, then we reverted that when we found another fix, but maybe not fully? However, I'll locate the spot in the commit history where it changed (if it's not too far in the remote past!), before proceeding. |
The use of |
PS Version of the historical commit without yellow highlighting: 4a933eb (line 826). |
I'm OK with your proposal, as long as you test it with various ZIM files (notably stackoverflow) and link types (like geo: etc) |
Will do :-) |
@mossroy : Just to let you know your memory was correct, and there is a difference between what is returned by I'm looking at the best options in the light of this. Thanks for your caution! |
Nice work! I just regret that I did not add a comment in the code to explain that. |
I'll definitely add a comment to explain. Just FYI, in case you're curious, here's what I found out:
Unfortunately, jQuery's Therefore we're back to Option 2, using I'll revert the revert and test more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not test, but the code looks good.
Thanks for the comments, that are very necessary.
Thanks @mossroy , I ran out of time this week, and I need to do a bit more testing of this PR in different scenarios. I aim to do that at the weekend, after which I'll squash/merge if I find no more issues with the code. It's interesting how what I thought at first would be a "little fix" turned out to have far more complications than I'd realized! |
b65a3c5
to
3365885
Compare
This problem is a bit tricky. In essence, the malformed href causes a crash on any attempt to access any property of the href. This means we have two choices: use jQuery, with its in-built error handling, or else we have to use try … catch. So I'm posting two commits here, one with jQuery and the second with try … catch. Both solve the issue. @mossroy , if you prefer the jQuery solution, or a variant of it, I'll revert the second commit. Although generally I prefer not to use jQuery when it's unnecessary, here I think it provides a tangible benefit, so I'm inclined towards the jQuery solution.