Skip to content

Commit

Permalink
Fix text files not writing escaped double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcashman committed Aug 5, 2020
1 parent 9537fe8 commit 5d31305
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public TextFile(InputStream inputStream, String relativePath, String commentForm
entry.getExtractedComments().add(line.substring(commentFormatPrefix.length()).trim());
} else {
entry.setReference(this.relativePath + ":" + lineNumber);
entry.setId(line);
entry.setId(Utils.escapeDoubleQuotes(line));
translationEntries.add(entry);
entry = null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*******************************************************************************
* Copyright 2020 Thomas Cashman
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package org.mini2Dx.gettext.plugin.file;

public class Utils {
public static String escapeDoubleQuotes(String str) {
return str.replace("\"", "\\\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public void testTextFile() throws IOException {
final List<TranslationEntry> results = new ArrayList<TranslationEntry>();
textFile.getTranslationEntries(results);

Assert.assertEquals(4, results.size());
Assert.assertEquals(5, results.size());

final TranslationEntry entry0 = results.get(0);
Assert.assertEquals(FILENAME + ":1", entry0.getReference());
Expand All @@ -41,5 +41,10 @@ public void testTextFile() throws IOException {
Assert.assertEquals(FILENAME + ":7", entry3.getReference());
Assert.assertEquals("Line 3", entry3.getId());
Assert.assertEquals(0, entry3.getExtractedComments().size());

final TranslationEntry entry4 = results.get(4);
Assert.assertEquals(FILENAME + ":10", entry4.getReference());
Assert.assertEquals("Line with \\\"Quotes\\\"", entry4.getId());
Assert.assertEquals(1, entry4.getExtractedComments().size());
}
}
5 changes: 4 additions & 1 deletion gettext-gradle-plugin/src/test/resources/sample.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ Line 1

#. Comment 1
Line 2
Line 3
Line 3

#. Comment 3
Line with "Quotes"

0 comments on commit 5d31305

Please sign in to comment.