diff --git a/src/Form/FlagConfirmBaseForm.php b/src/Form/FlagConfirmBaseForm.php
index 9e9b06f..8793cdb 100644
--- a/src/Form/FlagConfirmBaseForm.php
+++ b/src/Form/FlagConfirmBaseForm.php
@@ -10,6 +10,7 @@ use Drupal\Core\Form\ConfirmFormBase;
 use Drupal\Core\Url;
 use Drupal\Core\Form\FormStateInterface;
 use Drupal\flag\FlagInterface;
+use Drupal\Component\Utility\UrlHelper;
 
 /**
  * Provides methods common to the flag and unflag confirm forms.
@@ -48,12 +49,17 @@ abstract class FlagConfirmBaseForm extends ConfirmFormBase {
    * {@inheritdoc}
    */
   public function getCancelUrl() {
-    $destination = \Drupal::request()->get('destination');
-    if (!empty($destination)) {
-      return Url::createFromPath($destination);
+    $query = $this->getRequest()->query;
+
+    if ($query->has('destination')) {
+      $options = UrlHelper::parse($query->get('destination'));
+      $url = Url::fromUri('internal:/' . $options['path'], $options);
+    }
+    else {
+      $url = $this->entity->toUrl();
     }
 
-    return $this->entity->urlInfo();
+    return $url;
   }
 
 }
diff --git a/src/Form/FlaggingConfirmForm.php b/src/Form/FlaggingConfirmForm.php
index 61618fb..cea7ef4 100644
--- a/src/Form/FlaggingConfirmForm.php
+++ b/src/Form/FlaggingConfirmForm.php
@@ -6,6 +6,7 @@
 
 namespace Drupal\flag\Form;
 
+use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Form\ConfirmFormBase;
 use Drupal\Core\Url;
 use Drupal\Core\Form\FormStateInterface;
@@ -68,12 +69,17 @@ class FlaggingConfirmForm extends ConfirmFormBase {
    * {@inheritdoc}
    */
   public function getCancelUrl() {
-    $destination = \Drupal::request()->get('destination');
-    if (!empty($destination)) {
-      return Url::createFromPath($destination);
+    $query = $this->getRequest()->query;
+
+    if ($query->has('destination')) {
+      $options = UrlHelper::parse($query->get('destination'));
+      $url = Url::fromUri('internal:/' . $options['path'], $options);
+    }
+    else {
+      $url = $this->entity->toUrl();
     }
 
-    return $this->entity->urlInfo();
+    return $url;
   }
 
   /**
