Skip to content

Commit

Permalink
parse tag attributes that contain dashes
Browse files Browse the repository at this point in the history
The regex is wrong, it will also match attr names like `a-` or `-b?` or
even `-`, which are of course not valid.

Since the whole concept of sacy is centered around parsing
developer-supplied html and doesn't use a full-blown parser, I feel
the compromise is acceptable here in order to keep the regex simple.
  • Loading branch information
brainlock committed May 18, 2012
1 parent e6adb1f commit 9127015
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sacy/sacy.php
Expand Up @@ -81,7 +81,9 @@ function workUnitFromTag($tag, $attrdata, $content){
}

private function extract_attrs($attstr){
$attextract = '#([a-z]+)\s*=\s*(["\'])\s*(.*?)\s*\2#';
// The attribute name regex is too relaxed, but let's
// compromise and keep it simple.
$attextract = '#([a-z\-]+)\s*=\s*(["\'])\s*(.*?)\s*\2#';
if (!preg_match_all($attextract, $attstr, $m)) return false;
$res = array();
foreach($m[1] as $idx => $name){
Expand Down

0 comments on commit 9127015

Please sign in to comment.