aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/bookmark/LinkUtilsTest.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-11-08 13:54:39 +0100
committerArthurHoaro <arthur@hoa.ro>2020-11-08 13:54:39 +0100
commit00d3dd91ef42df13eeafbcc54dcebe3238e322c6 (patch)
tree123066f497546ad181c96ef2bdd1fde011457807 /tests/bookmark/LinkUtilsTest.php
parent8c5f6c786d00310b2e863aa316927effb7bfeedb (diff)
downloadShaarli-00d3dd91ef42df13eeafbcc54dcebe3238e322c6.tar.gz
Shaarli-00d3dd91ef42df13eeafbcc54dcebe3238e322c6.tar.zst
Shaarli-00d3dd91ef42df13eeafbcc54dcebe3238e322c6.zip
Fix an issue truncating extracted metadata content
Previous regex forced the selection to stop at either the first single or double quote found, regardless of the opening quote. Using '\1', we're sure to wait for the proper quote before stopping the capture.
Diffstat (limited to 'tests/bookmark/LinkUtilsTest.php')
-rw-r--r--tests/bookmark/LinkUtilsTest.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/bookmark/LinkUtilsTest.php b/tests/bookmark/LinkUtilsTest.php
index 3321242f..9bddf84b 100644
--- a/tests/bookmark/LinkUtilsTest.php
+++ b/tests/bookmark/LinkUtilsTest.php
@@ -169,6 +169,36 @@ class LinkUtilsTest extends TestCase
169 } 169 }
170 170
171 /** 171 /**
172 * Test html_extract_tag() with double quoted content containing single quote, and the opposite.
173 */
174 public function testHtmlExtractExistentNameTagWithMixedQuotes(): void
175 {
176 $description = 'Bob and Alice share M&M\'s.';
177
178 $html = '<meta property="og:description" content="' . $description . '">';
179 $this->assertEquals($description, html_extract_tag('description', $html));
180
181 $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
182 'tag2="content2" content="' . $description . '" tag3="content3">';
183 $this->assertEquals($description, html_extract_tag('description', $html));
184
185 $html = '<meta property="og:description" name="description" content="' . $description . '">';
186 $this->assertEquals($description, html_extract_tag('description', $html));
187
188 $description = 'Bob and Alice share "cookies".';
189
190 $html = '<meta property="og:description" content=\'' . $description . '\'>';
191 $this->assertEquals($description, html_extract_tag('description', $html));
192
193 $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
194 'tag2="content2" content=\'' . $description . '\' tag3="content3">';
195 $this->assertEquals($description, html_extract_tag('description', $html));
196
197 $html = '<meta property="og:description" name="description" content=\'' . $description . '\'>';
198 $this->assertEquals($description, html_extract_tag('description', $html));
199 }
200
201 /**
172 * Test html_extract_tag() when the tag <meta name= is not found. 202 * Test html_extract_tag() when the tag <meta name= is not found.
173 */ 203 */
174 public function testHtmlExtractNonExistentNameTag() 204 public function testHtmlExtractNonExistentNameTag()