From 3092e879645adb12f9b433cf0c2686ea30048244 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Sat, 25 Jun 2016 23:50:39 -0700 Subject: [PATCH] Added failing tests and fix for classes with numbers and in camelCase. --- Mf2/Parser.php | 1 + tests/Mf2/ParserTest.php | 78 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index 3717c58..0e72564 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -127,6 +127,7 @@ function unicodeTrim($str) { function mfNamesFromClass($class, $prefix='h-') { $class = str_replace(array(' ', ' ', "\n"), ' ', $class); $classes = explode(' ', $class); + $classes = preg_grep('#^[a-z\-]+$#', $classes); $matches = array(); foreach ($classes as $classname) { diff --git a/tests/Mf2/ParserTest.php b/tests/Mf2/ParserTest.php index 30e59d9..fa892d7 100644 --- a/tests/Mf2/ParserTest.php +++ b/tests/Mf2/ParserTest.php @@ -422,4 +422,82 @@ public function testWhitespaceBetweenElements() { $this->assertContains('h-entry', $output['items'][0]['type']); $this->assertNotContains('attendingHomebrew', $output['items'][0]['properties']['name'][0]); } + + + /** + * @see http://www.kevinmarks.com/twitterutils.html + */ + public function testCamelCaseClassNames() { + $input = << + +
+
+ + +
+

I wish people would stop using u- as a prefix for utility classes in CSS. Use util- instead. You're messing with my microformats.

+ + + + + + +
+
+
+ +EOT; + + $output = Mf2\parse($input); + + $this->assertArrayNotHasKey('linkBlend', $output['items'][0]['properties']); + $this->assertArrayNotHasKey('hiddenInNarrowEnv', $output['items'][0]['properties']); + $this->assertArrayNotHasKey('floatRight', $output['items'][0]['properties']); + } + + + public function testClassNameNumbers() { + $input = '

Test

'; + $output = Mf2\parse($input); + + $this->assertArrayNotHasKey('column1', $output['items'][0]['properties']); + } + }