Skip to content

The single quote breaks the strings in Android. We should escape them#88

Open
ctarabusi wants to merge 2 commits into
netbe:masterfrom
ctarabusi:fix-android-single-quote-escaping
Open

The single quote breaks the strings in Android. We should escape them#88
ctarabusi wants to merge 2 commits into
netbe:masterfrom
ctarabusi:fix-android-single-quote-escaping

Conversation

@ctarabusi

Copy link
Copy Markdown

Hi Francois,
I hope you are well, would you care to review this PR and eventually merge it?

Comment thread lib/babelish/csv2android.rb Outdated
def process_value(row_value, default_value)
value = super(row_value, default_value)
# if the value begins and ends with a quote we must leave them unescapted
value.gsub!(/'/, {"'" => "\\'"}) # escape single quote only for Android

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.
Space inside { missing.
Space inside } missing.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling 95ba087 on ctarabusi:fix-android-single-quote-escaping into * on netbe:master*.

@coveralls

Copy link
Copy Markdown

Coverage Status

Changes Unknown when pulling bc97884 on ctarabusi:fix-android-single-quote-escaping into * on netbe:master*.

@netbe

netbe commented Mar 31, 2016

Copy link
Copy Markdown
Owner

@ctarabusi sure just check the unit tests on travis, they are not passing right now.
Also if you care to help on the android stuff, #79 #74, #73

@netbe

netbe commented Aug 22, 2016

Copy link
Copy Markdown
Owner

Hey @ctarabusi, please rebase with master and fix tests:

Failure: test_converting_csv_with_special_chars(TestCSV2Android)
/Users/netbe/Code/Babelish/test/babelish/test_csv2android.rb:19:in `test_converting_csv_with_special_chars'
     16:     converter = Babelish::CSV2Android.new(csv_file, "german" => "de")
     17:     converter.convert
     18:     assert File.exist?("values-de/strings.xml"), "the ouptut file does not exist"
  => 19:     assert_equal File.read("test/data/android_special_chars_test_result.xml"), File.read("values-de/strings.xml")
     20:
     21:     # clean up
     22:     system("rm -rf ./values-de")
<"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n\t<string name=\"good_example_1\">This\\'ll work</string>\n\t<string name=\"good_example_2\">This is a \\\"good string\\\".</string>\n\t<string name=\"good_example_3\">\"This'll also work\"</string>\n\t<string name=\"welcome_messages_1\">Hello, %1$s! You have %2$d new messages.</string>\n\t<string name=\"welcome_messages_2\">Hello, %1$s! You have &lt;b&gt;%2$d new messages&lt;/b&gt;.</string>\n\t<string name=\"ANOTHER_STRING\">text <b>with</b> html and \\' special # chars ` ´ !\\\"§$%/()==?{[]}</string>\n\t<string name=\"title\">Title of &lt;a href=\\\"asd\\\"&gt;File&lt;/a&gt;</string>\n</resources>\n"> expected but was
<"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n\t<string name=\"good_example_1\">This\\\\'ll work</string>\n\t<string name=\"good_example_2\">This is a \\\"good string\\\".</string>\n\t<string name=\"good_example_3\">\"This\\'ll also work\"</string>\n\t<string name=\"welcome_messages_1\">Hello, %1$s! You have %2$d new messages.</string>\n\t<string name=\"welcome_messages_2\">Hello, %1$s! You have &lt;b&gt;%2$d new messages&lt;/b&gt;.</string>\n\t<string name=\"ANOTHER_STRING\">text <b>with</b> html and \\\\' special # chars ` ´ !\\\"§$%/()==?{[]}</string>\n\t<string name=\"title\">Title of &lt;a href=\\\"asd\\\"&gt;File&lt;/a&gt;</string>\n</resources>\n">

diff:
  <?xml version="1.0" encoding="utf-8"?>
  <resources>
?   <string name="good_example_1">This\\'ll work</string>
    <string name="good_example_2">This is a \"good string\".</string>
?   <string name="good_example_3">"This\'ll also work"</string>
    <string name="welcome_messages_1">Hello, %1$s! You have %2$d new messages.</string>
    <string name="welcome_messages_2">Hello, %1$s! You have &lt;b&gt;%2$d new messages&lt;/b&gt;.</string>
?   <string name="ANOTHER_STRING">text <b>with</b> html and \\' special # chars ` ´ !\"§$%/()==?{[]}</string>
    <string name="title">Title of &lt;a href=\"asd\"&gt;File&lt;/a&gt;</string>
  </resources>

@netbe

netbe commented Oct 13, 2016

Copy link
Copy Markdown
Owner

@ctarabusi any interest in finishing/commenting on the state of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants