From 5fe6d68b6482c62d0d41d399b2f2f45581f81404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20R=C4=85czka?= Date: Fri, 13 Nov 2015 13:45:12 +0100 Subject: [PATCH 1/4] adds assertion to test multibyte with multiple tags case --- tests/ProcessorTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ProcessorTest.php b/tests/ProcessorTest.php index 3f212b6..9bc7e01 100644 --- a/tests/ProcessorTest.php +++ b/tests/ProcessorTest.php @@ -64,6 +64,7 @@ public function provideTexts() array('[content]象形字[/content]', '象形字'), array('xxx [content]象形字[/content] yyy', 'xxx 象形字 yyy'), array('xxx [content]ąćęłńóśżź ąćęłńóśżź[/content] yyy', 'xxx ąćęłńóśżź ąćęłńóśżź yyy'), + array('xxx [content]żółć[/content] żółć[content]ąćęłńóśżź ąćęłńóśżź[/content] yyy', 'xxx żółć żółćąćęłńóśżź ąćęłńóśżź yyy'), array('[name]random[/other]', 'namerandom[/other]'), array('[name][other]random[/other]', 'name[other]random[/other]'), array('[content]random-[name]-random[/content]', 'random-name-random'), From d697d217b81cc0886ed05f1cdfe1cf347785c54f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20R=C4=85czka?= Date: Fri, 13 Nov 2015 14:01:01 +0100 Subject: [PATCH 2/4] Changes multibyte support and replacement function --- src/Processor/Processor.php | 6 ++++-- tests/ProcessorTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index 6efe674..45f97ad 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -65,14 +65,16 @@ private function processIteration($text, ProcessorContext $context, ShortcodeInt $this->prepareHandlerContext($shortcode, $context); $handler = $this->handlers->get($shortcode->getName()); $replace = $this->processHandler($shortcode, $context, $handler); - $length = mb_strlen($shortcode->getText()); + $length = strlen($shortcode->getText()); + // $length = mb_strlen($shortcode->getText()); $replaces[] = array($replace, $shortcode->getOffset(), $length); } $replaces = array_reverse(array_filter($replaces)); return array_reduce($replaces, function ($state, array $item) { - return mb_substr($state, 0, $item[1]).$item[0].mb_substr($state, $item[1] + $item[2]); + // return mb_substr($state, 0, $item[1]).$item[0].mb_substr($state, $item[1] + $item[2]); + return substr_replace($state, $item[0], $item[1], $item[2]); }, $text); } diff --git a/tests/ProcessorTest.php b/tests/ProcessorTest.php index 9bc7e01..11059a7 100644 --- a/tests/ProcessorTest.php +++ b/tests/ProcessorTest.php @@ -64,7 +64,7 @@ public function provideTexts() array('[content]象形字[/content]', '象形字'), array('xxx [content]象形字[/content] yyy', 'xxx 象形字 yyy'), array('xxx [content]ąćęłńóśżź ąćęłńóśżź[/content] yyy', 'xxx ąćęłńóśżź ąćęłńóśżź yyy'), - array('xxx [content]żółć[/content] żółć[content]ąćęłńóśżź ąćęłńóśżź[/content] yyy', 'xxx żółć żółćąćęłńóśżź ąćęłńóśżź yyy'), + array(', [content size="50px"]co ważne![/content] [c]Dzięki Tobie[/c] dzieci [content]uczą[/content] się wygrywać!', ', co ważne! Dzięki Tobie dzieci uczą się wygrywać!'), array('[name]random[/other]', 'namerandom[/other]'), array('[name][other]random[/other]', 'name[other]random[/other]'), array('[content]random-[name]-random[/content]', 'random-name-random'), From 20ea5ccba0173c77e7e7762a0284be19f1e7504f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20R=C4=85czka?= Date: Fri, 13 Nov 2015 14:11:25 +0100 Subject: [PATCH 3/4] Changes composer package name to allow subpackage install --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 045db0d..a701a88 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "thunderer/shortcode", + "name": "stowarzyszenia-wiosna/shortcode", "description": "Advanced shortcode (BBCode) parser and engine for PHP", "keywords": ["shortcode", "bbcode", "parser", "engine", "library"], "license": "MIT", From d9034191c9beb047cf4042d70e33320ae9b840fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20R=C4=85czka?= Date: Fri, 4 Dec 2015 10:51:13 +0100 Subject: [PATCH 4/4] Fix typo --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a701a88..6989aa7 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "stowarzyszenia-wiosna/shortcode", + "name": "stowarzyszenie-wiosna/shortcode", "description": "Advanced shortcode (BBCode) parser and engine for PHP", "keywords": ["shortcode", "bbcode", "parser", "engine", "library"], "license": "MIT",