]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Fix update method escapeUnescapedConfig 621/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 2 Aug 2016 10:54:55 +0000 (12:54 +0200)
committerArthurHoaro <arthur@hoa.ro>
Tue, 2 Aug 2016 10:54:55 +0000 (12:54 +0200)
  * Actually run it
  * unit tests

Fixes #611

application/Updater.php
tests/Updater/UpdaterTest.php

index fd45d17fd4dcbb4b411518cf5c98ebdbce6b8119..b6cbc56c4b2834a2c05b5cc7a7a4b554add554fa 100644 (file)
@@ -198,11 +198,11 @@ class Updater
      * 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')));
index 6bdce08b2c77c385f2f5c385c1eb3869c43ae86d..0d0ad92220cac1fef8fc954e645066854c7f555a 100644 (file)
@@ -263,4 +263,28 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
         $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');
+    }
 }