[iOS] Do not linkify telephone numbers inside <a> elements.
authorzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 May 2019 19:41:53 +0000 (19:41 +0000)
committerzalan@apple.com <zalan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 May 2019 19:41:53 +0000 (19:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=198378

Reviewed by Chris Dumez.

Source/WebCore:

Phone number linkifying mutates the DOM in a potentially unexpected way triggering different kinds of failures with JS, CSS selectors etc.
This patch tightens the linkifying rule so that content inside an <a> element won't get linkified even when the <a> has no valid href attribute.

Test: fast/dom/linkify-phone-numbers.html

* html/parser/HTMLTreeBuilder.cpp:
(WebCore::disallowTelephoneNumberParsing):

LayoutTests:

* fast/dom/linkify-phone-numbers-expected.html: Added.
* fast/dom/linkify-phone-numbers.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@245900 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/dom/linkify-phone-numbers-expected.html [new file with mode: 0644]
LayoutTests/fast/dom/linkify-phone-numbers.html [new file with mode: 0644]
LayoutTests/platform/ios/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/parser/HTMLTreeBuilder.cpp

index 39889c2..d19da36 100644 (file)
@@ -1,3 +1,13 @@
+2019-05-30  Zalan Bujtas  <zalan@apple.com>
+
+        [iOS] Do not linkify telephone numbers inside <a> elements.
+        https://bugs.webkit.org/show_bug.cgi?id=198378
+
+        Reviewed by Chris Dumez.
+
+        * fast/dom/linkify-phone-numbers-expected.html: Added.
+        * fast/dom/linkify-phone-numbers.html: Added.
+
 2019-05-30  Jer Noble  <jer.noble@apple.com>
 
         Video playback in Safari should continue when CarPlay is plugged in
index d7dc37c..d9293c2 100644 (file)
@@ -3101,3 +3101,6 @@ webkit.org/b/196274 imported/w3c/web-platform-tests/xhr/send-redirect-post-uploa
 webkit.org/b/157743 imported/w3c/web-platform-tests/resize-observer/eventloop.html [ Pass Failure ]
 
 webkit.org/b/198103 imported/w3c/web-platform-tests/html/semantics/embedded-content/media-elements/offsets-into-the-media-resource/currentTime.html [ Pass Failure ]
+
+# iOS only
+fast/dom/linkify-phone-numbers.html [ ImageOnlyFailure ]
diff --git a/LayoutTests/fast/dom/linkify-phone-numbers-expected.html b/LayoutTests/fast/dom/linkify-phone-numbers-expected.html
new file mode 100644 (file)
index 0000000..649b585
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests the most common cases of linkifying/not linkifying phone numbers on iOS</title>
+</head>
+<body>
+<a href="tel:408 111 222">408 111 222</a><br>
+<span><a href="tel:408 111 222">408 111 222</a></span>
+<div><a href="tel:408 111 222">408 111 222</a></div>
+<a>408 111 222</a><br>
+<a href="foobar.html">408 111 222</a>
+<pre>408 111 222</pre>
+<code>408 111 222</code>
+</body>
+</html>
diff --git a/LayoutTests/fast/dom/linkify-phone-numbers.html b/LayoutTests/fast/dom/linkify-phone-numbers.html
new file mode 100644 (file)
index 0000000..9c3fadf
--- /dev/null
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>This tests the most common cases of linkifying/not linkifying phone numbers on iOS</title>
+<script>
+if (window.internals)
+    internals.settings.setTelephoneNumberParsingEnabled(true);
+</script>
+</head>
+<body>
+408 111 222<br>
+<span>408 111 222</span>
+<div>408 111 222</div>
+<a>408 111 222</a><br>
+<a href="#">408 111 222</a>
+<pre>408 111 222</pre>
+<code>408 111 222</code>
+</body>
+</html>
index b5bf208..d9fed77 100644 (file)
@@ -2224,6 +2224,9 @@ webkit.org/b/148806 imported/w3c/web-platform-tests/css/css-multicol/multicol-sh
 webkit.org/b/148806 imported/w3c/web-platform-tests/css/css-multicol/multicol-span-all-block-sibling-003.xht [ ImageOnlyFailure ]
 webkit.org/b/148806 imported/w3c/web-platform-tests/css/css-multicol/multicol-span-all-margin-nested-firstchild-001.xht [ ImageOnlyFailure ]
 
+# Enable "phone number linkifying" test for iOS
+fast/dom/linkify-phone-numbers.html [ Pass ]
+
 # Enable "aria-current" test for iOS
 webkit.org/b/149297 accessibility/aria-current.html [ Pass ]
 
index f58fc4f..80f83bd 100644 (file)
@@ -1,3 +1,18 @@
+2019-05-30  Zalan Bujtas  <zalan@apple.com>
+
+        [iOS] Do not linkify telephone numbers inside <a> elements.
+        https://bugs.webkit.org/show_bug.cgi?id=198378
+
+        Reviewed by Chris Dumez.
+
+        Phone number linkifying mutates the DOM in a potentially unexpected way triggering different kinds of failures with JS, CSS selectors etc.
+        This patch tightens the linkifying rule so that content inside an <a> element won't get linkified even when the <a> has no valid href attribute.
+
+        Test: fast/dom/linkify-phone-numbers.html
+
+        * html/parser/HTMLTreeBuilder.cpp:
+        (WebCore::disallowTelephoneNumberParsing):
+
 2019-05-30  Truitt Savell  <tsavell@apple.com>
 
         Unreviewed, rolling out r245883.
index dedb8a5..18fbe40 100644 (file)
@@ -2258,6 +2258,7 @@ void HTMLTreeBuilder::linkifyPhoneNumbers(const String& string)
 static inline bool disallowTelephoneNumberParsing(const ContainerNode& node)
 {
     return node.isLink()
+        || node.hasTagName(aTag)
         || node.hasTagName(scriptTag)
         || is<HTMLFormControlElement>(node)
         || node.hasTagName(styleTag)