From 6ac906d244c8ed16f7b4bc08f8d915b348dd74e5 Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 18:09:13 +0800 Subject: [PATCH 1/7] Workaround to fix cdata problem --- lib/babelish/android2csv.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/babelish/android2csv.rb b/lib/babelish/android2csv.rb index b6e6ffd..32753dc 100644 --- a/lib/babelish/android2csv.rb +++ b/lib/babelish/android2csv.rb @@ -15,7 +15,10 @@ def load_strings(strings_filename) end parser.xpath("//string").each do |node| if !node.nil? && !node["name"].nil? - strings.merge!(node["name"] => node.inner_html) + if node.cdata? + strings.merge!(node["name"] => '') + else + strings.merge!(node["name"] => node.inner_html) end end From c7bdf9db0bff1ef6389ce45a21ee4d2dfb965b4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franc=CC=A7ois=20Benaiteau?= Date: Mon, 9 Nov 2015 19:27:37 +0100 Subject: [PATCH 2/7] Add test for handling CDATA in android2csv --- test/babelish/test_android2csv.rb | 20 ++++++++++++++++++++ test/data/android_cdata.xml | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 test/data/android_cdata.xml diff --git a/test/babelish/test_android2csv.rb b/test/babelish/test_android2csv.rb index d38a43e..a61b290 100644 --- a/test/babelish/test_android2csv.rb +++ b/test/babelish/test_android2csv.rb @@ -50,4 +50,24 @@ def test_special_chars # clean up system("rm -rf ./" + csv_filename) end + + def test_cdata_are_not_removed + csv_filename = "./test.csv" + filename = "test/data/android_cdata.xml" + headers = %w{variables german} + + expected_output = [["html"], {filename => {"html" => "Text

]]>"}}] + converter = Babelish::Android2CSV.new( + :csv_filename => csv_filename, + :headers => headers, + :filenames => [filename]) + + output = converter.convert(false) + + assert File.exist?(converter.csv_filename) + assert_equal expected_output, output + + # clean up + system("rm -rf ./" + csv_filename) + end end diff --git a/test/data/android_cdata.xml b/test/data/android_cdata.xml new file mode 100644 index 0000000..29189d0 --- /dev/null +++ b/test/data/android_cdata.xml @@ -0,0 +1,4 @@ + + +Text

]]> + From ea498e84438e87dcb15356544c90baa7df82024d Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 18:36:19 +0800 Subject: [PATCH 3/7] Fix missing end --- lib/babelish/android2csv.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/babelish/android2csv.rb b/lib/babelish/android2csv.rb index 32753dc..8a699b8 100644 --- a/lib/babelish/android2csv.rb +++ b/lib/babelish/android2csv.rb @@ -19,6 +19,7 @@ def load_strings(strings_filename) strings.merge!(node["name"] => '') else strings.merge!(node["name"] => node.inner_html) + end end end From 9863f907edb29c1939a948517c90a6f2e1c2d7ce Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 18:39:06 +0800 Subject: [PATCH 4/7] Fix advices from houndci --- lib/babelish/android2csv.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/babelish/android2csv.rb b/lib/babelish/android2csv.rb index 8a699b8..13c870f 100644 --- a/lib/babelish/android2csv.rb +++ b/lib/babelish/android2csv.rb @@ -16,10 +16,10 @@ def load_strings(strings_filename) parser.xpath("//string").each do |node| if !node.nil? && !node["name"].nil? if node.cdata? - strings.merge!(node["name"] => '') + strings.merge!(node["name"] => "") else strings.merge!(node["name"] => node.inner_html) - end + end end end From f66672a6d8dd050d2191fb4bf5f401d09d235def Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 18:53:40 +0800 Subject: [PATCH 5/7] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 81e17c8..ee7b914 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ *~ *# #*# +.DS_Store # Config file .babelish From e1284d5ae2ebd850657bfe685bf33b9be2eea525 Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 19:44:32 +0800 Subject: [PATCH 6/7] Modify the test, try another workaround --- lib/babelish/android2csv.rb | 2 +- test/babelish/test_android2csv.rb | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/babelish/android2csv.rb b/lib/babelish/android2csv.rb index 13c870f..0a989a5 100644 --- a/lib/babelish/android2csv.rb +++ b/lib/babelish/android2csv.rb @@ -15,7 +15,7 @@ def load_strings(strings_filename) end parser.xpath("//string").each do |node| if !node.nil? && !node["name"].nil? - if node.cdata? + if "#{node.children.first.class}" == "Nokogiri::XML::CDATA" strings.merge!(node["name"] => "") else strings.merge!(node["name"] => node.inner_html) diff --git a/test/babelish/test_android2csv.rb b/test/babelish/test_android2csv.rb index a61b290..802c6e5 100644 --- a/test/babelish/test_android2csv.rb +++ b/test/babelish/test_android2csv.rb @@ -64,7 +64,6 @@ def test_cdata_are_not_removed output = converter.convert(false) - assert File.exist?(converter.csv_filename) assert_equal expected_output, output # clean up From 005cf5a45d9132eda3d439a8dcfeddb3b4a68beb Mon Sep 17 00:00:00 2001 From: Anderson Lin Date: Wed, 7 Mar 2018 20:02:23 +0800 Subject: [PATCH 7/7] Fix advices from houndci --- lib/babelish/android2csv.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/babelish/android2csv.rb b/lib/babelish/android2csv.rb index 0a989a5..d8d777a 100644 --- a/lib/babelish/android2csv.rb +++ b/lib/babelish/android2csv.rb @@ -15,7 +15,7 @@ def load_strings(strings_filename) end parser.xpath("//string").each do |node| if !node.nil? && !node["name"].nil? - if "#{node.children.first.class}" == "Nokogiri::XML::CDATA" + if node.children.first.class.to_s == "Nokogiri::XML::CDATA" strings.merge!(node["name"] => "") else strings.merge!(node["name"] => node.inner_html)