mirrored from git://git.moodle.org/moodle.git
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-31785 import HTMLPurifier 4.4.0+
Includes one extra fix for _blank 8c9d461a6259d7b8ac4ae5c9c9e95ab176cfcda3 compared to 4.4.0 release.
- Loading branch information
Showing
46 changed files
with
1,026 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Validates based on {ident} CSS grammar production | ||
*/ | ||
class HTMLPurifier_AttrDef_CSS_Ident extends HTMLPurifier_AttrDef | ||
{ | ||
|
||
public function validate($string, $config, $context) { | ||
|
||
$string = trim($string); | ||
|
||
// early abort: '' and '0' (strings that convert to false) are invalid | ||
if (!$string) return false; | ||
|
||
$pattern = '/^(-?[A-Za-z_][A-Za-z_\-0-9]*)$/'; | ||
if (!preg_match($pattern, $string)) return false; | ||
return $string; | ||
|
||
} | ||
|
||
} | ||
|
||
// vim: et sw=4 sts=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* Dummy AttrDef that mimics another AttrDef, BUT it generates clones | ||
* with make. | ||
*/ | ||
class HTMLPurifier_AttrDef_Clone extends HTMLPurifier_AttrDef | ||
{ | ||
/** | ||
* What we're cloning | ||
*/ | ||
protected $clone; | ||
|
||
public function __construct($clone) { | ||
$this->clone = $clone; | ||
} | ||
|
||
public function validate($v, $config, $context) { | ||
return $this->clone->validate($v, $config, $context); | ||
} | ||
|
||
public function make($string) { | ||
return clone $this->clone; | ||
} | ||
|
||
} | ||
|
||
// vim: et sw=4 sts=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
lib/htmlpurifier/HTMLPurifier/AttrTransform/TargetBlank.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
// must be called POST validation | ||
|
||
/** | ||
* Adds target="blank" to all outbound links. This transform is | ||
* only attached if Attr.TargetBlank is TRUE. This works regardless | ||
* of whether or not Attr.AllowedFrameTargets | ||
*/ | ||
class HTMLPurifier_AttrTransform_TargetBlank extends HTMLPurifier_AttrTransform | ||
{ | ||
private $parser; | ||
|
||
public function __construct() { | ||
$this->parser = new HTMLPurifier_URIParser(); | ||
} | ||
|
||
public function transform($attr, $config, $context) { | ||
|
||
if (!isset($attr['href'])) { | ||
return $attr; | ||
} | ||
|
||
// XXX Kind of inefficient | ||
$url = $this->parser->parse($attr['href']); | ||
$scheme = $url->getSchemeObj($config, $context); | ||
|
||
if ($scheme->browsable && !$url->isBenign($config, $context)) { | ||
$attr['target'] = '_blank'; | ||
} | ||
|
||
return $attr; | ||
|
||
} | ||
|
||
} | ||
|
||
// vim: et sw=4 sts=4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.