commit 1f177fed7729fcc7c10c6dd87d4d2aa96258711e
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Nov 2 16:23:28 2015 +0100

    Allow quotes in PDF text properties
    
    PDF properties (Author, Title...) need to be quoted properly when writing 
(normal operation and tex2lyx). Also, reading them requires to use 
Lexer::getString() directly, because >> uses next(), which does not handle 
escapes.
    
    Fixes bug #9830.

diff --git a/src/PDFOptions.cpp b/src/PDFOptions.cpp
index 7de277c..d0bc2a2 100644
--- a/src/PDFOptions.cpp
+++ b/src/PDFOptions.cpp
@@ -61,13 +61,13 @@ void PDFOptions::writeFile(ostream & os) const
                return;
        
        if (!title.empty() )
-               os << "\\pdf_title \"" << title << "\"\n";
+               os << "\\pdf_title " << Lexer::quoteString(title) << '\n';
        if (!author.empty())
-               os << "\\pdf_author \"" << author << "\"\n";
+               os << "\\pdf_author " << Lexer::quoteString(author) << '\n';
        if (!subject.empty())
-               os << "\\pdf_subject \"" << subject << "\"\n";
+               os << "\\pdf_subject " << Lexer::quoteString(subject) << '\n';
        if (!keywords.empty())
-               os << "\\pdf_keywords \"" << keywords << "\"\n";
+               os << "\\pdf_keywords " << Lexer::quoteString(keywords) << '\n';
        
        
        os << "\\pdf_bookmarks " << convert<string>(bookmarks) << '\n';
@@ -85,7 +85,7 @@ void PDFOptions::writeFile(ostream & os) const
                os << "\\pdf_pagemode " << pagemode << '\n';
        
        if (!quoted_options.empty())
-               os << "\\pdf_quoted_options \"" << quoted_options << "\"\n";
+               os << "\\pdf_quoted_options " << 
Lexer::quoteString(quoted_options) << '\n';
 }
 
 
@@ -206,13 +206,25 @@ string PDFOptions::readToken(Lexer &lex, string const & 
token)
        if (token == "\\use_hyperref") {
                lex >> use_hyperref;
        } else if (token == "\\pdf_title") {
-               lex >> title;
+               if (lex.isOK()) {
+                       lex.next(true);
+                       title = lex.getString();
+               }
        } else if (token == "\\pdf_author") {
-               lex >> author;
+               if (lex.isOK()) {
+                       lex.next(true);
+                       author = lex.getString();
+               }
        } else if (token == "\\pdf_subject") {
-               lex >> subject;
+               if (lex.isOK()) {
+                       lex.next(true);
+                       subject = lex.getString();
+               }
        } else if (token == "\\pdf_keywords") {
-               lex >> keywords;
+               if (lex.isOK()) {
+                       lex.next(true);
+                       keywords = lex.getString();
+               }
        } else if (token == "\\pdf_bookmarks") {
                lex >> bookmarks;
        } else if (token == "\\pdf_bookmarksnumbered") {
@@ -234,7 +246,10 @@ string PDFOptions::readToken(Lexer &lex, string const & 
token)
        } else if (token == "\\pdf_pagemode") {
                lex >> pagemode;
        } else if (token == "\\pdf_quoted_options") {
-               lex >> quoted_options;
+               if (lex.isOK()) {
+                       lex.next(true);
+                       quoted_options = lex.getString();
+               }
        } else {
                return token;
        }
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 65d978f..9e75b09 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -1151,13 +1151,13 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
           << "\\use_hyperref " << h_use_hyperref << '\n';
        if (h_use_hyperref == "true") {
                if (!h_pdf_title.empty())
-                       os << "\\pdf_title \"" << h_pdf_title << "\"\n";
+                       os << "\\pdf_title " << Lexer::quoteString(h_pdf_title) 
<< '\n';
                if (!h_pdf_author.empty())
-                       os << "\\pdf_author \"" << h_pdf_author << "\"\n";
+                       os << "\\pdf_author " << 
Lexer::quoteString(h_pdf_author) << '\n';
                if (!h_pdf_subject.empty())
-                       os << "\\pdf_subject \"" << h_pdf_subject << "\"\n";
+                       os << "\\pdf_subject " << 
Lexer::quoteString(h_pdf_subject) << '\n';
                if (!h_pdf_keywords.empty())
-                       os << "\\pdf_keywords \"" << h_pdf_keywords << "\"\n";
+                       os << "\\pdf_keywords " << 
Lexer::quoteString(h_pdf_keywords) << '\n';
                os << "\\pdf_bookmarks " << h_pdf_bookmarks << "\n"
                      "\\pdf_bookmarksnumbered " << h_pdf_bookmarksnumbered << 
"\n"
                      "\\pdf_bookmarksopen " << h_pdf_bookmarksopen << "\n"
@@ -1170,7 +1170,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
                if (!h_pdf_pagemode.empty())
                        os << "\\pdf_pagemode " << h_pdf_pagemode << '\n';
                if (!h_pdf_quoted_options.empty())
-                       os << "\\pdf_quoted_options \"" << h_pdf_quoted_options 
<< "\"\n";
+                       os << "\\pdf_quoted_options " << 
Lexer::quoteString(h_pdf_quoted_options) << '\n';
        }
        os << "\\papersize " << h_papersize << "\n"
           << "\\use_geometry " << h_use_geometry << '\n';
diff --git a/status.21x b/status.21x
index af81e74..a8de5c8 100644
--- a/status.21x
+++ b/status.21x
@@ -105,6 +105,8 @@ What's new
 - Another attempt to fix NSAutoreleasePool related crashes within LinkBack
   driver. Now there is no global static pool used anymore (bug 8637).
 
+- Allow quotes in PDF text properties (bug 9830).
+
 
 
 * DOCUMENTATION AND LOCALIZATION

Reply via email to