[DRE-commits] [ruby-org] 70/303: More test cases for custom keywords. Fixed bug: HTML not escaped in headings.

Jérémy Bobbio lunar at alioth.debian.org
Fri Aug 9 17:33:29 UTC 2013


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

lunar pushed a commit to branch master
in repository ruby-org.

commit 16e428bca3f022c0e671968be75e0438677901f7
Author: Brian Dewey <bdewey at gmail.com>
Date:   Tue Dec 29 23:51:17 2009 -0800

    More test cases for custom keywords. Fixed bug: HTML not escaped in headings.
---
 History.txt                                        |    3 +
 lib/org-ruby/headline.rb                           |   10 +-
 .../{custom-todo.html => custom-seq-todo.html}     |    2 +-
 .../{custom-todo.org => custom-seq-todo.org}       |    0
 spec/html_examples/custom-todo.html                |    2 +-
 spec/html_examples/custom-todo.org                 |    2 +-
 .../{custom-todo.html => custom-typ-todo.html}     |    2 +-
 .../{custom-todo.org => custom-typ-todo.org}       |    2 +-
 spec/html_examples/entities.html                   |    1 +
 spec/html_examples/entities.org                    |    3 +
 spec/parser_spec.rb                                |  102 ++++++++++----------
 11 files changed, 74 insertions(+), 55 deletions(-)

diff --git a/History.txt b/History.txt
index 1606762..ea93d11 100644
--- a/History.txt
+++ b/History.txt
@@ -7,9 +7,12 @@
   * Numbering headlines (option num:t)
   * Skipping text before the first headline (option skip:t)
   * Skipping tables (option |:nil)
+  * Custom todo keywords
 * Rewrite "file:(blah).org" links to "http:(blah).html" links. This
   makes the inter-links to other org-mode files work.
 * Uses <th> tags inside table rows that precede table separators.
+* Bugfixes:
+  * Headings now have HTML escaped.
 
 == 0.4.2 / 2009-12-29
 
diff --git a/lib/org-ruby/headline.rb b/lib/org-ruby/headline.rb
index f49828c..70a222b 100644
--- a/lib/org-ruby/headline.rb
+++ b/lib/org-ruby/headline.rb
@@ -79,7 +79,7 @@ module Orgmode
       if @parser and @parser.export_todo? and @keyword then
         output << "<span class=\"todo-keyword #{@keyword}\">#{@keyword} </span>"
       end
-      output << "#{@headline_text}</h#{@level}>\n"
+      output << "#{escape(@headline_text)}</h#{@level}>\n"
       output << Line.to_html(@body_lines, opts)
       output
     end
@@ -87,6 +87,14 @@ module Orgmode
     ######################################################################
     private
 
+    # TODO 2009-12-29 This duplicates escape_buffer! in html_output_buffer. DRY.
+    def escape(str)
+      str = str.gsub(/&/, "&")
+      str = str.gsub(/</, "<")
+      str = str.gsub(/>/, ">")
+      str
+    end
+
     def parse_keywords
       re = @parser.custom_keyword_regexp if @parser
       re ||= KeywordsRegexp
diff --git a/spec/html_examples/custom-todo.html b/spec/html_examples/custom-seq-todo.html
similarity index 91%
copy from spec/html_examples/custom-todo.html
copy to spec/html_examples/custom-seq-todo.html
index 95dd5fe..2cb7712 100644
--- a/spec/html_examples/custom-todo.html
+++ b/spec/html_examples/custom-seq-todo.html
@@ -10,6 +10,6 @@
 <h1><span class="todo-keyword DONE">DONE </span>Finished this one!</h1>
 <h1><span class="todo-keyword CANCELED">CANCELED </span>I gave up here.</h1>
 <h1>DONT be fooled by just a random word in all caps.</h1>
-<h1>todo <== this word doesn't match because the case doesn't match.</h1>
+<h1>todo <== this word doesn’t match because the case doesn’t match.</h1>
 <h1>TODOX</h1>
 <p>don’t be fooled by the initial substring above!</p>
diff --git a/spec/html_examples/custom-todo.org b/spec/html_examples/custom-seq-todo.org
similarity index 100%
copy from spec/html_examples/custom-todo.org
copy to spec/html_examples/custom-seq-todo.org
diff --git a/spec/html_examples/custom-todo.html b/spec/html_examples/custom-todo.html
index 95dd5fe..2cb7712 100644
--- a/spec/html_examples/custom-todo.html
+++ b/spec/html_examples/custom-todo.html
@@ -10,6 +10,6 @@
 <h1><span class="todo-keyword DONE">DONE </span>Finished this one!</h1>
 <h1><span class="todo-keyword CANCELED">CANCELED </span>I gave up here.</h1>
 <h1>DONT be fooled by just a random word in all caps.</h1>
-<h1>todo <== this word doesn't match because the case doesn't match.</h1>
+<h1>todo <== this word doesn’t match because the case doesn’t match.</h1>
 <h1>TODOX</h1>
 <p>don’t be fooled by the initial substring above!</p>
diff --git a/spec/html_examples/custom-todo.org b/spec/html_examples/custom-todo.org
index 2ab839a..f8b5b44 100644
--- a/spec/html_examples/custom-todo.org
+++ b/spec/html_examples/custom-todo.org
@@ -1,6 +1,6 @@
 #+TITLE: custom-todo.org
 #+DESCRIPTION: Makes sure I can handle custom todo entries
-#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
+#+TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
 #+OPTIONS:    todo:t
 
 I copied this todo sequence from Worg. It shows a lot of power of the
diff --git a/spec/html_examples/custom-todo.html b/spec/html_examples/custom-typ-todo.html
similarity index 91%
copy from spec/html_examples/custom-todo.html
copy to spec/html_examples/custom-typ-todo.html
index 95dd5fe..2cb7712 100644
--- a/spec/html_examples/custom-todo.html
+++ b/spec/html_examples/custom-typ-todo.html
@@ -10,6 +10,6 @@
 <h1><span class="todo-keyword DONE">DONE </span>Finished this one!</h1>
 <h1><span class="todo-keyword CANCELED">CANCELED </span>I gave up here.</h1>
 <h1>DONT be fooled by just a random word in all caps.</h1>
-<h1>todo <== this word doesn't match because the case doesn't match.</h1>
+<h1>todo <== this word doesn’t match because the case doesn’t match.</h1>
 <h1>TODOX</h1>
 <p>don’t be fooled by the initial substring above!</p>
diff --git a/spec/html_examples/custom-todo.org b/spec/html_examples/custom-typ-todo.org
similarity index 92%
copy from spec/html_examples/custom-todo.org
copy to spec/html_examples/custom-typ-todo.org
index 2ab839a..7e0b2eb 100644
--- a/spec/html_examples/custom-todo.org
+++ b/spec/html_examples/custom-typ-todo.org
@@ -1,6 +1,6 @@
 #+TITLE: custom-todo.org
 #+DESCRIPTION: Makes sure I can handle custom todo entries
-#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
+#+TYP_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
 #+OPTIONS:    todo:t
 
 I copied this todo sequence from Worg. It shows a lot of power of the
diff --git a/spec/html_examples/entities.html b/spec/html_examples/entities.html
index cc33c69..9724256 100644
--- a/spec/html_examples/entities.html
+++ b/spec/html_examples/entities.html
@@ -1,3 +1,4 @@
 <p class="title">ENTITIES</p>
 <p><code>Org-ruby</code> supports “smart double quotes,” ‘smart single quotes,’ apostrophes for contractions like won’t and can’t, and other things… like elipses. Oh – and dashes.</p>
 <p>Question: What does org-mode do for ampersands, like R&R? or &lt;? Answer: Those get escaped, too.</p>
+<h1><Even in headlines! funner & funner!></h1>
diff --git a/spec/html_examples/entities.org b/spec/html_examples/entities.org
index 77ecf60..51268e6 100644
--- a/spec/html_examples/entities.org
+++ b/spec/html_examples/entities.org
@@ -6,3 +6,6 @@ things... like elipses. Oh -- and dashes.
 
 Question: What does org-mode do for ampersands, like R&R? or <?
 Answer: Those get escaped, too.
+
+* <Even in headlines! funner & funner!>
+
diff --git a/spec/parser_spec.rb b/spec/parser_spec.rb
index 64c386f..a84456f 100644
--- a/spec/parser_spec.rb
+++ b/spec/parser_spec.rb
@@ -92,61 +92,65 @@ describe Orgmode::Parser do
     p.export_tables?.should be_false
   end
 
-  # Custom keywords -- dynamic test cases
-  fname = File.join(File.dirname(__FILE__), %w[html_examples custom-todo.org])
-  p = Orgmode::Parser.load(fname)
-  puts p.custom_keyword_regexp.to_s
-  valid_keywords = %w[TODO INPROGRESS WAITING DONE CANCELED]
-  invalid_keywords = %w[TODOX todo inprogress Waiting done cANCELED NEXT |]
-  valid_keywords.each do |kw|
-    it "should match custom keyword #{kw}" do
-      (kw =~ p.custom_keyword_regexp).should be_true
+  describe "Custom keyword parser" do
+    fname = File.join(File.dirname(__FILE__), %w[html_examples custom-todo.org])
+    p = Orgmode::Parser.load(fname)
+    valid_keywords = %w[TODO INPROGRESS WAITING DONE CANCELED]
+    invalid_keywords = %w[TODOX todo inprogress Waiting done cANCELED NEXT |]
+    valid_keywords.each do |kw|
+      it "should match custom keyword #{kw}" do
+        (kw =~ p.custom_keyword_regexp).should be_true
+      end
     end
-  end
-  invalid_keywords.each do |kw|
-    it "should not match custom keyword #{kw}" do
-      (kw =~ p.custom_keyword_regexp).should be_nil
+    invalid_keywords.each do |kw|
+      it "should not match custom keyword #{kw}" do
+        (kw =~ p.custom_keyword_regexp).should be_nil
+      end
+    end
+    it "should not match blank as a custom keyword" do
+      ("" =~ p.custom_keyword_regexp).should be_nil
     end
   end
-  it "should not match blank as a custom keyword" do
-    ("" =~ p.custom_keyword_regexp).should be_nil
-  end
-
-  data_directory = File.join(File.dirname(__FILE__), "textile_examples")
-  org_files = File.expand_path(File.join(data_directory, "*.org" ))
-  files = Dir.glob(org_files)
-  files.each do |file|
-    basename = File.basename(file, ".org")
-    textile_name = File.join(data_directory, basename + ".textile")
-    textile_name = File.expand_path(textile_name)
-
-    it "should convert #{basename}.org to Textile" do
-      expected = IO.read(textile_name)
-      expected.should be_kind_of(String)
-      parser = Orgmode::Parser.new(IO.read(file))
-      actual = parser.to_textile
-      actual.should be_kind_of(String)
-      actual.should == expected
+
+  describe "Export to Textile test cases" do
+    data_directory = File.join(File.dirname(__FILE__), "textile_examples")
+    org_files = File.expand_path(File.join(data_directory, "*.org" ))
+    files = Dir.glob(org_files)
+    files.each do |file|
+      basename = File.basename(file, ".org")
+      textile_name = File.join(data_directory, basename + ".textile")
+      textile_name = File.expand_path(textile_name)
+
+      it "should convert #{basename}.org to Textile" do
+        expected = IO.read(textile_name)
+        expected.should be_kind_of(String)
+        parser = Orgmode::Parser.new(IO.read(file))
+        actual = parser.to_textile
+        actual.should be_kind_of(String)
+        actual.should == expected
+      end
     end
   end
 
-  # Dynamic generation of examples from each *.org file in html_examples.
-  # Each of these files is convertable to HTML.
-  data_directory = File.join(File.dirname(__FILE__), "html_examples")
-  org_files = File.expand_path(File.join(data_directory, "*.org" ))
-  files = Dir.glob(org_files)
-  files.each do |file|
-    basename = File.basename(file, ".org")
-    textile_name = File.join(data_directory, basename + ".html")
-    textile_name = File.expand_path(textile_name)
-
-    it "should convert #{basename}.org to HTML" do
-      expected = IO.read(textile_name)
-      expected.should be_kind_of(String)
-      parser = Orgmode::Parser.new(IO.read(file))
-      actual = parser.to_html
-      actual.should be_kind_of(String)
-      actual.should == expected
+  describe "Export to HTML test cases" do
+    # Dynamic generation of examples from each *.org file in html_examples.
+    # Each of these files is convertable to HTML.
+    data_directory = File.join(File.dirname(__FILE__), "html_examples")
+    org_files = File.expand_path(File.join(data_directory, "*.org" ))
+    files = Dir.glob(org_files)
+    files.each do |file|
+      basename = File.basename(file, ".org")
+      textile_name = File.join(data_directory, basename + ".html")
+      textile_name = File.expand_path(textile_name)
+
+      it "should convert #{basename}.org to HTML" do
+        expected = IO.read(textile_name)
+        expected.should be_kind_of(String)
+        parser = Orgmode::Parser.new(IO.read(file))
+        actual = parser.to_html
+        actual.should be_kind_of(String)
+        actual.should == expected
+      end
     end
   end
 end

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-org.git



More information about the Pkg-ruby-extras-commits mailing list