From b508ed2260a9fd9951a0b7536514be7ff2609ae3 Mon Sep 17 00:00:00 2001 From: David Rosca Date: Thu, 14 Feb 2019 08:44:42 +0100 Subject: [PATCH] WebHitTestResult: Expect null href attribute Patch by Eugene Shalygin BUG: 404320 --- src/lib/webengine/webhittestresult.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/webengine/webhittestresult.cpp b/src/lib/webengine/webhittestresult.cpp index 318f77ec5..fb0224e04 100644 --- a/src/lib/webengine/webhittestresult.cpp +++ b/src/lib/webengine/webhittestresult.cpp @@ -48,6 +48,9 @@ WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos) " return false;" " return window.getSelection().containsNode(e, true);" "}" + "function attributeStr(e, a) {" + " return e.getAttribute(a) || '';" + "}" "var res = {" " baseUrl: document.baseURI," " alternateText: e.getAttribute('alt')," @@ -63,16 +66,16 @@ WebHitTestResult::WebHitTestResult(const WebPage *page, const QPoint &pos) "var r = e.getBoundingClientRect();" "res.boundingRect = [r.top, r.left, r.width, r.height];" "if (e.tagName.toLowerCase() == 'img')" - " res.imageUrl = e.getAttribute('src').trim();" + " res.imageUrl = attributeStr(e, 'src').trim();" "if (e.tagName.toLowerCase() == 'a') {" " res.linkTitle = e.text;" - " res.linkUrl = e.getAttribute('href').trim();" + " res.linkUrl = attributeStr(e, 'href').trim();" "}" "while (e) {" " if (res.linkTitle == '' && e.tagName.toLowerCase() == 'a')" " res.linkTitle = e.text;" " if (res.linkUrl == '' && e.tagName.toLowerCase() == 'a')" - " res.linkUrl = e.getAttribute('href').trim();" + " res.linkUrl = attributeStr(e, 'href').trim();" " if (res.mediaUrl == '' && isMediaElement(e)) {" " res.mediaUrl = e.currentSrc;" " res.mediaPaused = e.paused;"