Skip to content

Commit

Permalink
Escaped hyphens in regex character classes
Browse files Browse the repository at this point in the history
The hyphens triggered warnings in PHP v7.3.0. Escaping them can be done safely, since it is compatible with other versions of PHP, which were simply a little more tolerant.

A bit more information can be found here: https://stackoverflow.com/questions/26208622/preg-match-compilation-failed-invalid-range-in-character-class-at-offset-15
  • Loading branch information
Mistralys authored Sep 7, 2018
1 parent a971f20 commit 3988f23
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions simple_html_dom.php
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ protected function parse_selector($selector_string) {
// This implies that an html attribute specifier may start with an @ sign that is NOT captured by the expression.
// farther study is required to determine of this should be documented or removed.
// $pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
$pattern = "/([\w-:\*]*)(?:\#([\w-]+)|\.([\w-]+))?(?:\[@?(!?[\w-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
$pattern = "/([\w\-:\*]*)(?:\#([\w\-]+)|\.([\w\-]+))?(?:\[@?(!?[\w\-:]+)(?:([!*^$]?=)[\"']?(.*?)[\"']?)?\])?([\/, ]+)/is";
preg_match_all($pattern, trim($selector_string).' ', $matches, PREG_SET_ORDER);
if (is_object($debugObject)) {$debugObject->debugLog(2, "Matches Array: ", $matches);}

Expand Down Expand Up @@ -927,7 +927,7 @@ function get_display_size()
{
// Thanks to user gnarf from stackoverflow for this regular expression.
$attributes = array();
preg_match_all("/([\w-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER);
preg_match_all("/([\w\-]+)\s*:\s*([^;]+)\s*;?/", $this->attr['style'], $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$attributes[$match[1]] = $match[2];
}
Expand Down Expand Up @@ -1402,7 +1402,7 @@ protected function read_tag()
return true;
}

if (!preg_match("/^[\w-:]+$/", $tag)) {
if (!preg_match("/^[\w\-:]+$/", $tag)) {
$node->_[HDOM_INFO_TEXT] = '<' . $tag . $this->copy_until('<>');
if ($this->char==='<') {
$this->link_nodes($node, false);
Expand Down

0 comments on commit 3988f23

Please sign in to comment.