Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try Fix CDATA problem in android2csv.rb #104

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*~
*#
#*#
.DS_Store

# Config file
.babelish
Expand Down
6 changes: 5 additions & 1 deletion lib/babelish/android2csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ 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.children.first.class.to_s == "Nokogiri::XML::CDATA"
strings.merge!(node["name"] => "<![CDATA[" + node.inner_html + "]]>")
else
strings.merge!(node["name"] => node.inner_html)
end
end
end

Expand Down
19 changes: 19 additions & 0 deletions test/babelish/test_android2csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,23 @@ 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" => "<![CDATA[<p>Text<p>]]>"}}]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Line is too long. [84/80]
Space inside } missing.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space inside { missing.
Line is too long. [84/80]
Space inside } missing.

converter = Babelish::Android2CSV.new(
:csv_filename => csv_filename,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:headers => headers,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

:filenames => [filename])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Closing method call brace must be on the line after the last argument when opening brace is on a separate line from the first argument.


output = converter.convert(false)

Copy link
Author

@trisix trisix Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remove a line here which check if file exists.

Since the above convert has a false. I think the file will not exist?

assert_equal expected_output, output

# clean up
system("rm -rf ./" + csv_filename)
end
end
4 changes: 4 additions & 0 deletions test/data/android_cdata.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="html"><![CDATA[<p>Text<p>]]></string>
</resources>