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 3 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
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.cdata?
strings.merge!(node["name"] => '<![CDATA[' + node.inner_html + ']]>')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [81/80]

else
strings.merge!(node["name"] => node.inner_html)
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Trailing whitespace detected.

end
end

Expand Down
20 changes: 20 additions & 0 deletions test/babelish/test_android2csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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" => "<![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 File.exist?(converter.csv_filename)
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>