Skip to content

Commit

Permalink
Merge pull request #621 from ArthurHoaro/hotfix/update-escape-config
Browse files Browse the repository at this point in the history
Fix update method escapeUnescapedConfig
  • Loading branch information
virtualtam authored Aug 2, 2016
2 parents 58f0660 + b9f8b83 commit c7a42ab
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions application/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ public function updateMethodConfigToJson()
* Escape settings which have been manually escaped in every request in previous versions:
* - general.title
* - general.header_link
* - extras.redirector
* - redirector.url
*
* @return bool true if the update is successful, false otherwise.
*/
public function escapeUnescapedConfig()
public function updateMethodEscapeUnescapedConfig()
{
try {
$this->conf->set('general.title', escape($this->conf->get('general.title')));
Expand Down
24 changes: 24 additions & 0 deletions tests/Updater/UpdaterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,28 @@ public function testConfigToJsonNothingToDo()
$expected = filemtime($this->conf->getConfigFileExt());
$this->assertEquals($expected, $filetime);
}

/**
* Test escapeUnescapedConfig with valid data.
*/
public function testEscapeConfig()
{
$sandbox = 'sandbox/config';
copy(self::$configFile .'.json.php', $sandbox .'.json.php');
$this->conf = new ConfigManager($sandbox);
$title = '<script>alert("title");</script>';
$headerLink = '<script>alert("header_link");</script>';
$redirectorUrl = '<script>alert("redirector");</script>';
$this->conf->set('general.title', $title);
$this->conf->set('general.header_link', $headerLink);
$this->conf->set('redirector.url', $redirectorUrl);
$updater = new Updater(array(), array(), $this->conf, true);
$done = $updater->updateMethodEscapeUnescapedConfig();
$this->assertTrue($done);
$this->conf->reload();
$this->assertEquals(escape($title), $this->conf->get('general.title'));
$this->assertEquals(escape($headerLink), $this->conf->get('general.header_link'));
$this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
unlink($sandbox .'.json.php');
}
}

0 comments on commit c7a42ab

Please sign in to comment.