Просмотр исходного кода

Merge pull request #2624 from kaishuu0123/fix/copy-to-clipboard-anchor-link

Fix "Copy to clipboard" anchor link
Yuki Takei 5 лет назад
Родитель
Сommit
175ace661d
1 измененных файлов с 11 добавлено и 2 удалено
  1. 11 2
      src/client/js/components/Page/CopyDropdown.jsx

+ 11 - 2
src/client/js/components/Page/CopyDropdown.jsx

@@ -55,6 +55,15 @@ class CopyDropdown extends React.Component {
     return `${search}${hash}`;
   }
 
+  encodeSpaces(str) {
+    if (str == null) {
+      return null;
+    }
+
+    // Encode SPACE and IDEOGRAPHIC SPACE
+    return str.replace(/ /g, '%20').replace(/\u3000/g, '%E3%80%80');
+  }
+
   generatePagePathWithParams() {
     const { pagePath } = this.props;
     return decodeURI(`${pagePath}${this.uriParams}`);
@@ -62,7 +71,7 @@ class CopyDropdown extends React.Component {
 
   generatePagePathUrl() {
     const { origin } = window.location;
-    return `${origin}${this.generatePagePathWithParams()}`;
+    return `${origin}${this.encodeSpaces(this.generatePagePathWithParams())}`;
   }
 
   generatePermalink() {
@@ -75,7 +84,7 @@ class CopyDropdown extends React.Component {
       return decodeURI(`${origin}/share/${pageId}`);
     }
 
-    return decodeURI(`${origin}/${pageId}${this.uriParams}`);
+    return decodeURI(`${origin}/${pageId}`) + this.encodeSpaces(decodeURI(this.uriParams));
   }
 
   generateMarkdownLink() {