]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Merge pull request #1621 from ArthurHoaro/feature/tag-separators
authorArthurHoaro <arthur@hoa.ro>
Sun, 8 Nov 2020 13:07:33 +0000 (14:07 +0100)
committerGitHub <noreply@github.com>
Sun, 8 Nov 2020 13:07:33 +0000 (14:07 +0100)
application/bookmark/BookmarkInitializer.php
application/bookmark/LinkUtils.php
application/front/controller/visitor/ErrorController.php
assets/default/scss/shaarli.scss
inc/languages/fr/LC_MESSAGES/shaarli.po
tests/bookmark/LinkUtilsTest.php
tests/front/controller/visitor/ErrorControllerTest.php
tpl/default/error.html

index 04b996f3e6500edc13d8e96353ede55ad250323d..98dd3f1c1ed62e1fb5291807ffb744127afc57f0 100644 (file)
@@ -36,8 +36,8 @@ class BookmarkInitializer
     public function initialize(): void
     {
         $bookmark = new Bookmark();
-        $bookmark->setTitle('quicksilver (loop) on Vimeo ' . t('(private bookmark with thumbnail demo)'));
-        $bookmark->setUrl('https://vimeo.com/153493904');
+        $bookmark->setTitle('Calm Jazz Music - YouTube ' . t('(private bookmark with thumbnail demo)'));
+        $bookmark->setUrl('https://www.youtube.com/watch?v=DVEUcbPkb-c');
         $bookmark->setDescription(t(
 'Shaarli will automatically pick up the thumbnail for links to a variety of websites.
 
index 9493b0aa894e00de160684be54dc3f8ab4aa4bab..cf97e3b0a904a08d72a5ee7d3467efb1536f5c96 100644 (file)
@@ -68,16 +68,16 @@ function html_extract_tag($tag, $html)
     $properties = implode('|', $propertiesKey);
     // We need a OR here to accept either 'property=og:noquote' or 'property="og:unrelated og:my-tag"'
     $orCondition  = '["\']?(?:og:)?'. $tag .'["\']?|["\'][^\'"]*?(?:og:)?' . $tag . '[^\'"]*?[\'"]';
-    // Try to retrieve OpenGraph image.
-    $ogRegex = '#<meta[^>]+(?:'. $properties .')=(?:'. $orCondition .')[^>]*content=["\'](.*?)["\'].*?>#';
+    // Try to retrieve OpenGraph tag.
+    $ogRegex = '#<meta[^>]+(?:'. $properties .')=(?:'. $orCondition .')[^>]*content=(["\'])([^\1]*?)\1.*?>#';
     // If the attributes are not in the order property => content (e.g. Github)
     // New regex to keep this readable... more or less.
-    $ogRegexReverse = '#<meta[^>]+content=["\'](.*?)["\'][^>]+(?:'. $properties .')=(?:'. $orCondition .').*?>#';
+    $ogRegexReverse = '#<meta[^>]+content=(["\'])([^\1]*?)\1[^>]+(?:'. $properties .')=(?:'. $orCondition .').*?>#';
 
     if (preg_match($ogRegex, $html, $matches) > 0
         || preg_match($ogRegexReverse, $html, $matches) > 0
     ) {
-        return $matches[1];
+        return $matches[2];
     }
 
     return false;
index 8da11172ffa52c6c8ae5967760b5a5043c05cca7..428e82542df2b56695c05db30e3e68269fe09437 100644 (file)
@@ -26,8 +26,14 @@ class ErrorController extends ShaarliVisitorController
             $response = $response->withStatus($throwable->getCode());
         } else {
             // Internal error (any other Throwable)
-            if ($this->container->conf->get('dev.debug', false)) {
-                $this->assignView('message', $throwable->getMessage());
+            if ($this->container->conf->get('dev.debug', false) || $this->container->loginManager->isLoggedIn()) {
+                $this->assignView('message', t('Error: ') . $throwable->getMessage());
+                $this->assignView(
+                    'text',
+                    '<a href="https://github.com/shaarli/Shaarli/issues/new">'
+                    . t('Please report it on Github.')
+                    . '</a>'
+                );
                 $this->assignView('stacktrace', exception2text($throwable));
             } else {
                 $this->assignView('message', t('An unexpected error occurred.'));
@@ -36,7 +42,6 @@ class ErrorController extends ShaarliVisitorController
             $response = $response->withStatus(500);
         }
 
-
         return $response->write($this->render('error'));
     }
 }
index ed774a9d6e63cacb9564155c1dc3523c14e85623..cc8ccc1e0d4811de5b526e65d886f0b820058606 100644 (file)
@@ -1276,11 +1276,15 @@ form {
     margin: 70px 0 25px;
   }
 
+  a {
+    color: var(--main-color);
+  }
+
   pre {
     margin: 0 20%;
     padding: 20px 0;
     text-align: left;
-    line-height: .7em;
+    line-height: 1em;
   }
 }
 
index 4c363fa8669a5f46f6317de81de6a41cb2170d12..51bef6c7df76fc2621c5c1b566274a44a7905162 100644 (file)
@@ -1,8 +1,8 @@
 msgid ""
 msgstr ""
 "Project-Id-Version: Shaarli\n"
-"POT-Creation-Date: 2020-11-05 16:47+0100\n"
-"PO-Revision-Date: 2020-11-05 16:48+0100\n"
+"POT-Creation-Date: 2020-11-05 19:43+0100\n"
+"PO-Revision-Date: 2020-11-05 19:44+0100\n"
 "Last-Translator: \n"
 "Language-Team: Shaarli\n"
 "Language: fr_FR\n"
@@ -501,7 +501,15 @@ msgstr "mois"
 msgid "Monthly"
 msgstr "Mensuel"
 
-#: application/front/controller/visitor/ErrorController.php:33
+#: application/front/controller/visitor/ErrorController.php:30
+msgid "Error: "
+msgstr "Erreur : "
+
+#: application/front/controller/visitor/ErrorController.php:34
+msgid "Please report it on Github."
+msgstr "Merci de la rapporter sur Github."
+
+#: application/front/controller/visitor/ErrorController.php:39
 msgid "An unexpected error occurred."
 msgstr "Une erreur inattendue s'est produite."
 
index c2f9f9305716829b91ba6ffe36cfc9a8a29cb80e..ddab4e3caebd0e7070273738054f9f58d0821aa0 100644 (file)
@@ -168,6 +168,36 @@ class LinkUtilsTest extends TestCase
         $this->assertEquals($description, html_extract_tag('description', $html));
     }
 
+    /**
+     * Test html_extract_tag() with double quoted content containing single quote, and the opposite.
+     */
+    public function testHtmlExtractExistentNameTagWithMixedQuotes(): void
+    {
+        $description = 'Bob and Alice share M&M\'s.';
+
+        $html = '<meta property="og:description" content="' . $description . '">';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+
+        $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
+            'tag2="content2" content="' . $description . '" tag3="content3">';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+
+        $html = '<meta property="og:description" name="description" content="' . $description . '">';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+
+        $description = 'Bob and Alice share "cookies".';
+
+        $html = '<meta property="og:description" content=\'' . $description . '\'>';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+
+        $html = '<meta tag1="content1" property="og:unrelated1 og:description og:unrelated2" '.
+            'tag2="content2" content=\'' . $description . '\' tag3="content3">';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+
+        $html = '<meta property="og:description" name="description" content=\'' . $description . '\'>';
+        $this->assertEquals($description, html_extract_tag('description', $html));
+    }
+
     /**
      * Test html_extract_tag() when the tag <meta name= is not found.
      */
index 75408cf4040e21297f049729213a63b21f915a3c..e18a6fa2faa278c99eb0071766cabd272ecf6036 100644 (file)
@@ -50,7 +50,31 @@ class ErrorControllerTest extends TestCase
     }
 
     /**
-     * Test displaying error with any exception (no debug): only display an error occurred with HTTP 500.
+     * Test displaying error with any exception (no debug) while logged in:
+     * display full error details
+     */
+    public function testDisplayAnyExceptionErrorNoDebugLoggedIn(): void
+    {
+        $request = $this->createMock(Request::class);
+        $response = new Response();
+
+        // Save RainTPL assigned variables
+        $assignedVariables = [];
+        $this->assignTemplateVars($assignedVariables);
+
+        $this->container->loginManager->method('isLoggedIn')->willReturn(true);
+
+        $result = ($this->controller)($request, $response, new \Exception('abc'));
+
+        static::assertSame(500, $result->getStatusCode());
+        static::assertSame('Error: abc', $assignedVariables['message']);
+        static::assertContainsPolyfill('Please report it on Github', $assignedVariables['text']);
+        static::assertArrayHasKey('stacktrace', $assignedVariables);
+    }
+
+    /**
+     * Test displaying error with any exception (no debug) while logged out:
+     * display standard error without detail
      */
     public function testDisplayAnyExceptionErrorNoDebug(): void
     {
@@ -61,10 +85,13 @@ class ErrorControllerTest extends TestCase
         $assignedVariables = [];
         $this->assignTemplateVars($assignedVariables);
 
+        $this->container->loginManager->method('isLoggedIn')->willReturn(false);
+
         $result = ($this->controller)($request, $response, new \Exception('abc'));
 
         static::assertSame(500, $result->getStatusCode());
         static::assertSame('An unexpected error occurred.', $assignedVariables['message']);
+        static::assertArrayNotHasKey('text', $assignedVariables);
         static::assertArrayNotHasKey('stacktrace', $assignedVariables);
     }
 }
index c3e0c3c1db3f914475fbf0d59fa6a3e349f684c1..34f9707dd2db00f589912bb0bc50210526ab3a59 100644 (file)
@@ -9,13 +9,17 @@
 <div id="pageError" class="page-error-container center">
   <h2>{$message}</h2>
 
+  <img src="{$asset_path}/img/sad_star.png#" alt="">
+
+  {if="!empty($text)"}
+  <p>{$text}</p>
+  {/if}
+
   {if="!empty($stacktrace)"}
       <pre>
         {$stacktrace}
       </pre>
   {/if}
-
-  <img src="{$asset_path}/img/sad_star.png#" alt="">
 </div>
 {include="page.footer"}
 </body>