[Pkg-javascript-commits] [pdf.js] 83/109: Add a utility function, for the viewer, that removes `null` (\x00) characters (issue 6416)

David Prévot taffit at moszumanska.debian.org
Fri Sep 25 03:04:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit b7d1bed46303e1639b143e34aad6f0322f7f0dc0
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Wed Sep 9 23:42:22 2015 +0200

    Add a utility function, for the viewer, that removes `null` (\x00) characters (issue 6416)
    
    Since some browsers render `null` characters, and others don't, this patch adds a way to remove them to prevent display issues in the viewer UI.
    
    Given that documents may contain very long outlines, I've added a utility function to avoid creating a lot of unnecessary `RegExp` objects.
    To avoid any future issues, this utility function is used for both the outline and the attachments.
    
    Fixes 6416.
---
 web/pdf_attachment_view.js | 4 ++--
 web/pdf_outline_view.js    | 3 ++-
 web/ui_utils.js            | 6 ++++++
 3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/web/pdf_attachment_view.js b/web/pdf_attachment_view.js
index df98b71..33247b6 100644
--- a/web/pdf_attachment_view.js
+++ b/web/pdf_attachment_view.js
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/* globals getFileName */
+/* globals getFileName, removeNullCharacters */
 
 'use strict';
 
@@ -91,7 +91,7 @@ var PDFAttachmentView = (function PDFAttachmentViewClosure() {
         div.className = 'attachmentsItem';
         var button = document.createElement('button');
         this._bindLink(button, item.content, filename);
-        button.textContent = filename;
+        button.textContent = removeNullCharacters(filename);
         div.appendChild(button);
         this.container.appendChild(div);
       }
diff --git a/web/pdf_outline_view.js b/web/pdf_outline_view.js
index 94b545f..d7602b5 100644
--- a/web/pdf_outline_view.js
+++ b/web/pdf_outline_view.js
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+/* globals removeNullCharacters */
 
 'use strict';
 
@@ -138,7 +139,7 @@ var PDFOutlineView = (function PDFOutlineViewClosure() {
           div.className = 'outlineItem';
           var element = document.createElement('a');
           this._bindLink(element, item);
-          element.textContent = item.title;
+          element.textContent = removeNullCharacters(item.title);
           div.appendChild(element);
 
           if (item.items.length > 0) {
diff --git a/web/ui_utils.js b/web/ui_utils.js
index e58b771..bd32684 100644
--- a/web/ui_utils.js
+++ b/web/ui_utils.js
@@ -75,6 +75,12 @@ var CustomStyle = (function CustomStyleClosure() {
   return CustomStyle;
 })();
 
+var NullCharactersRegExp = /\x00/g;
+
+function removeNullCharacters(str) {
+  return str.replace(NullCharactersRegExp, '');
+}
+
 function getFileName(url) {
   var anchor = url.indexOf('#');
   var query = url.indexOf('?');

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list