From 5d4ace919b843e181d5d966d3241046c5f2362e8 Mon Sep 17 00:00:00 2001 From: Jukka Svahn Date: Sun, 18 Nov 2018 12:23:06 +0200 Subject: [PATCH] Backport PHP >=7.2 compatibility --- .gitattributes | 1 + .travis.yml | 8 +++++--- CHANGELOG.textile | 6 ++++-- LICENSE | 2 +- README.textile | 2 +- composer.json | 14 ++++++++++---- phpcs.xml | 7 +++++++ phpunit.xml | 5 +++++ src/Netcarver/Textile/Parser.php | 19 +++++-------------- 9 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 phpcs.xml diff --git a/.gitattributes b/.gitattributes index cc158118..c4d217c9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ /test export-ignore /.gitignore export-ignore /.travis.yml export-ignore +/phpcs.xml export-ignore /phpunit.xml export-ignore /.gitattributes export-ignore diff --git a/.travis.yml b/.travis.yml index 294ccdd4..0b3985a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,16 @@ language: php php: - - 5.5 - - 5.4 + - 7.2 + - 7.1 + - 7.0 + - 5.6 - hhvm before_script: - composer install script: - - ./vendor/bin/phpcs --standard=PSR1,PSR2 src test + - ./vendor/bin/phpcs - ./vendor/bin/phpunit after_script: diff --git a/CHANGELOG.textile b/CHANGELOG.textile index 6f674638..84759141 100644 --- a/CHANGELOG.textile +++ b/CHANGELOG.textile @@ -2,7 +2,9 @@ h1. Changelog Here's a summary of changes in each release. The list doesn't include some small changes or updates to test cases. -h2. Version 3.5.6 - upcoming +h2. "Version 3.5.6 - 2018/11/18":https://github.com/textile/php-textile/releases/tag/v3.5.6 + +* Fix PHP >=7.2 compatibility. h2. "Version 3.5.5 - 2014/01/02":https://github.com/textile/php-textile/releases/tag/v3.5.5 @@ -22,7 +24,7 @@ h2. "Version 3.5.5 - 2014/01/02":https://github.com/textile/php-textile/releases h2. "Version 3.5.4 - 2013/11/06":https://github.com/textile/php-textile/releases/tag/v3.5.4 * Fix broken image alignment in HTML5 mode (closes "#123":https://github.com/textile/php-textile/issues/123). -* Fix duplicate HTML IDs that occur when a footnote isn't referenced in the content (closes "#125":https://github.com/textile/php-textile/issues/125). +* Fix duplicate HTML IDs that occur when a footnote isn't referenced in the content (closes "#125":https://github.com/textile/php-textile/issues/125). * Don't include image alignment to the URL in restricted mode. * Detect and process quoted quote symbols. * New link parser (closes "#86":https://github.com/textile/php-textile/issues/86, "#87":https://github.com/textile/php-textile/issues/87 and "#128":https://github.com/textile/php-textile/issues/128). diff --git a/LICENSE b/LICENSE index ba924f65..b9ed5837 100644 --- a/LICENSE +++ b/LICENSE @@ -9,7 +9,7 @@ Additions and fixes Copyright (c) 2010 Stef Dawson http://stefdawson.co Additions and fixes Copyright (c) 2010-13 Netcarver https://github.com/netcarver Additions and fixes Copyright (c) 2011 Jeff Soo http://ipsedixit.net/ Additions and fixes Copyright (c) 2012 Robert Wetzlmayr http://wetzlmayr.com/ -Additions and fixes Copyright (c) 2012-13 Jukka Svahn http://rahforum.biz/ +Additions and fixes Copyright (c) 2012-18 Jukka Svahn http://rahforum.biz/ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/README.textile b/README.textile index 896db2ca..9eee27fb 100644 --- a/README.textile +++ b/README.textile @@ -2,7 +2,7 @@ h1. PHP-Textile "Downloads":https://github.com/textile/php-textile/releases | "Textile reference":http://txstyle.org/article/43/a-short-introduction | "Live editor":http://txstyle.org/ | "Packagist":https://packagist.org/packages/netcarver/textile -!https://travis-ci.org/textile/php-textile.png?branch=master!:https://travis-ci.org/textile/php-textile !https://coveralls.io/repos/textile/php-textile/badge.png?branch=master!:https://coveralls.io/r/textile/php-textile?branch=master +!https://travis-ci.org/textile/php-textile.png?branch=3.5!:https://travis-ci.org/textile/php-textile !https://coveralls.io/repos/textile/php-textile/badge.png?branch=3.5!:https://coveralls.io/r/textile/php-textile?branch=3.5 PHP-Textile is a modern Textile markup language parser for PHP. Textile is a humane web text generator that takes lightweight, readable, plaintext-like markup language and converts it into well formed HTML. diff --git a/composer.json b/composer.json index 6a25f58d..a2285350 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,21 @@ "source": "https://github.com/textile/php-textile" }, "autoload": { - "psr-0": { "Netcarver\\Textile": "src/" } + "psr-4": { + "Netcarver\\Textile\\": "src/Netcarver/Textile/" + } }, "require": { "php": ">=5.3.0" }, "require-dev": { - "phpunit/phpunit": "3.7.*", - "symfony/yaml": "2.3.*", - "squizlabs/php_codesniffer": "1.5.*", + "phpunit/phpunit": "5.7.*", + "symfony/yaml": "2.4.*", + "squizlabs/php_codesniffer": "3.*", "satooshi/php-coveralls": "0.6.*" + }, + "scripts": { + "test": "./vendor/bin/phpunit", + "cs": "./vendor/bin/phpcs" } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100644 index 00000000..8b6eb699 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,7 @@ + + + src + test + + + diff --git a/phpunit.xml b/phpunit.xml index 64e424b3..78e59678 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -5,6 +5,11 @@ ./test/Netcarver/Textile/Test/ + + + ./src/ + + diff --git a/src/Netcarver/Textile/Parser.php b/src/Netcarver/Textile/Parser.php index 4c150ec3..233cfe7e 100644 --- a/src/Netcarver/Textile/Parser.php +++ b/src/Netcarver/Textile/Parser.php @@ -22,7 +22,7 @@ * Additions and fixes Copyright (c) 2010-13 Netcarver https://github.com/netcarver * Additions and fixes Copyright (c) 2011 Jeff Soo http://ipsedixit.net/ * Additions and fixes Copyright (c) 2012 Robert Wetzlmayr http://wetzlmayr.com/ - * Additions and fixes Copyright (c) 2012-13 Jukka Svahn http://rahforum.biz/ + * Additions and fixes Copyright (c) 2012-18 Jukka Svahn http://rahforum.biz/ * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -350,7 +350,7 @@ class Parser * @var string */ - protected $ver = '3.5.5'; + protected $ver = '3.5.6'; /** * Regular expression snippets. @@ -1508,7 +1508,7 @@ protected function formatAttributeString(array $attribute_array) protected function parseAttribsToArray($in, $element = '', $include_id = true, $autoclass = '') { - $style = ''; + $style = array(); $class = ''; $lang = ''; $colspan = ''; @@ -1552,7 +1552,6 @@ protected function parseAttribsToArray($in, $element = '', $include_id = true, $ } if (preg_match("/\(([^()]+)\)/U", $matched, $cls)) { - $class_regex = "/^([-a-zA-Z 0-9_\.]*)$/"; // Consume entire class block -- valid or invalid. @@ -1643,7 +1642,7 @@ protected function parseAttribsToArray($in, $element = '', $include_id = true, $ $o['span'] = $this->cleanAttribs($span); } - if ($style) { + if (!empty($style)) { $so = ''; $tmps = array(); foreach ($style as $s) { @@ -1661,9 +1660,8 @@ protected function parseAttribsToArray($in, $element = '', $include_id = true, $ $so .= $p.';'; } } - $style = trim(str_replace(array("\n", ';;'), array('', ';'), $so)); - $o['style'] = $style; + $o['style'] = trim(str_replace(array("\n", ';;'), array('', ';'), $so)); } if ($width) { @@ -1735,7 +1733,6 @@ protected function fTable($matches) $c_row = 1; foreach (preg_split("/\|{$space}*?$/m", $matches['rows'], -1, PREG_SPLIT_NO_EMPTY) as $row) { - $row = ltrim($row); // Caption -- can only occur on row 1, otherwise treat '|=. foo |...' @@ -2186,7 +2183,6 @@ protected function blocks($text) $out = array(); foreach ($textblocks as $block) { - // Line is just whitespace, keep it for the next block. if (trim($block) === '') { if ($eatWhitespace === false) { @@ -2257,7 +2253,6 @@ protected function blocks($text) } else { $whitespace = ''; } - } if ($ext) { @@ -3003,13 +2998,11 @@ protected function markStartOfLinks($text) $slices = preg_split('/":(?='.$this->regex_snippets['char'].')/'.$mod, $text); if (count($slices) > 1) { - // There are never any start of links in the last slice, so pop it // off (we'll glue it back later). $last_slice = array_pop($slices); foreach ($slices as &$slice) { - // If there is no possible start quote then this slice is not a link if (false === strpos($slice, '"')) { continue; @@ -3078,7 +3071,6 @@ protected function markStartOfLinks($text) array_push($possible_start_quotes, $possibility); break; } - } // Rebuild the link's text by reversing the parts and sticking them back @@ -3221,7 +3213,6 @@ protected function fLink($m) $c = array_pop($url_chars); $popped = false; switch ($c) { - // Textile URL shouldn't end in these characters, we pop // them off the end and push them out the back of the url again. case '!':