Skip to content

Commit

Permalink
Extend tag escaping strategy to quotes around attribute values
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Jan 11, 2019
1 parent 181df8c commit 2670a15
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,26 @@ class ParserEngine {
if (!translatable && !mConfig.allowNonTranslatableTranslation && builder.mQualifier != mConfig.defaultColumnName)
throw new IllegalArgumentException("$name is translated but marked translatable='false', row #${i + 1}")
}

TagEscapingStrategy strategy = mConfig.tagEscapingStrategy
if (sourceInfo.mTagEscapingStrategyIndex >= 0) {
def strategyName = row[sourceInfo.mTagEscapingStrategyIndex]
if (strategyName) {
strategy = TagEscapingStrategy.valueOf(strategyName)
}
}

if (!JAVA_IDENTIFIER_REGEX.matcher(name).matches()) {
if (mConfig.skipInvalidName)
continue
throw new IllegalArgumentException("$name is not valid name, row #${i + 1}")
}

if (mConfig.escapeSlashes)
value = value.replace("\\", "\\\\")
if (mConfig.escapeApostrophes)
value = value.replace("'", "\\'")
if (mConfig.escapeQuotes) //TODO don't escape tag attribute values
if (mConfig.escapeQuotes && (strategy == ALWAYS || (strategy == IF_TAGS_ABSENT && !Utils.containsHTML(value))))
value = value.replace("\"", "\\\"")
if (mConfig.escapeNewLines)
value = value.replace("\n", "\\n")
Expand All @@ -168,11 +183,6 @@ class ParserEngine {
if (mConfig.normalizationForm)
value = Normalizer.normalize(value, mConfig.normalizationForm)

if (!JAVA_IDENTIFIER_REGEX.matcher(name).matches()) {
if (mConfig.skipInvalidName)
continue
throw new IllegalArgumentException("$name is not valid name, row #${i + 1}")
}
if (resourceType == PLURAL || resourceType == ARRAY) {
//TODO require only one translatable value for all list?
if (resourceType == ARRAY) {
Expand All @@ -197,13 +207,6 @@ class ParserEngine {
continue
throw new IllegalArgumentException("$name is duplicated in row #${i + 1}")
}
TagEscapingStrategy strategy = mConfig.tagEscapingStrategy
if (sourceInfo.mTagEscapingStrategyIndex >= 0) {
def strategyName = row[sourceInfo.mTagEscapingStrategyIndex]
if (strategyName) {
strategy = TagEscapingStrategy.valueOf(strategyName)
}
}
string(stringAttrs) {
yieldValue(mkp, value, strategy)
}
Expand Down

0 comments on commit 2670a15

Please sign in to comment.