-
Notifications
You must be signed in to change notification settings - Fork 349
fix: Normalize param's names of "safe" object #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,12 @@ class HTMLPurifier_Injector_SafeObject extends HTMLPurifier_Injector | |
| 'allowNetworking' => 'internal', | ||
| ); | ||
|
|
||
| /** | ||
| * Lower-cased map for $addParam | ||
| * @type array | ||
| */ | ||
| protected $addParamMap = array(); | ||
|
|
||
| /** | ||
| * These are all lower-case keys. | ||
| * @type array | ||
|
|
@@ -47,6 +53,13 @@ class HTMLPurifier_Injector_SafeObject extends HTMLPurifier_Injector | |
| 'allowfullscreen' => true, // if omitted, assume to be 'false' | ||
| ); | ||
|
|
||
| public function __construct() | ||
| { | ||
| foreach (array_keys($this->addParam) as $name) { | ||
| $this->addParamMap[strtolower($name)] = $name; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @param HTMLPurifier_Config $config | ||
| * @param HTMLPurifier_Context $context | ||
|
|
@@ -64,11 +77,13 @@ public function handleElement(&$token) | |
| { | ||
| if ($token->name == 'object') { | ||
| $this->objectStack[] = $token; | ||
| $this->paramStack[] = array(); | ||
| $paramStack = array(); | ||
| $new = array($token); | ||
| foreach ($this->addParam as $name => $value) { | ||
| $new[] = new HTMLPurifier_Token_Empty('param', array('name' => $name, 'value' => $value)); | ||
| $paramStack[strtolower($name)] = true; | ||
| } | ||
| $this->paramStack[] = $paramStack; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From line 67: we've already added these parameters, so we must initialize the parameters stack with them to avoid duplicates later. |
||
| $token = $new; | ||
| } elseif ($token->name == 'param') { | ||
| $nest = count($this->currentNesting) - 1; | ||
|
|
@@ -78,23 +93,24 @@ public function handleElement(&$token) | |
| $token = false; | ||
| return; | ||
| } | ||
| $n = $token->attr['name']; | ||
| $n = strtolower($token->attr['name']); | ||
| // We need this fix because YouTube doesn't supply a data | ||
| // attribute, which we need if a type is specified. This is | ||
| // *very* Flash specific. | ||
| if (!isset($this->objectStack[$i]->attr['data']) && | ||
| ($token->attr['name'] == 'movie' || $token->attr['name'] == 'src') | ||
| ($n == 'movie' || $n == 'src') | ||
| ) { | ||
| $this->objectStack[$i]->attr['data'] = $token->attr['value']; | ||
| } | ||
| /** @TODO: fix comment */ | ||
| // Check if the parameter is the correct value but has not | ||
| // already been added | ||
| if (!isset($this->paramStack[$i][$n]) && | ||
| isset($this->addParam[$n]) && | ||
| $token->attr['name'] === $this->addParam[$n]) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It appears that there is a bug: the condition |
||
| isset($this->addParamMap[$n]) && | ||
| $token->attr['value'] === $this->addParam[$this->addParamMap[$n]]) { | ||
| // keep token, and add to param stack | ||
| $this->paramStack[$i][$n] = true; | ||
| } elseif (isset($this->allowedParam[strtolower($n)])) { | ||
| } elseif (isset($this->allowedParam[$n])) { | ||
| // keep token, don't do anything to it | ||
| // (could possibly check for duplicates here) | ||
| // Note: In principle, parameters should be case sensitive. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using null values instead of strings is deprecated in functions like
htmlspecialchars