Skip to content

Commit df606cb

Browse files
committed
Fix low priority maintenance and consistency issues
- StringsdictParser: Consolidate duplicate variable extraction logic - Android: Return null for empty plural forms (no valid items) - XLIFF: Reject null/empty plural values in ParsePluralGroup12
1 parent 6ecac4e commit df606cb

1 file changed

Lines changed: 17 additions & 10 deletions

File tree

LocalizationManager.Core/Backends/iOS/StringsdictParser.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License
33

44
using System.Text;
5+
using System.Xml;
56
using System.Xml.Linq;
67

78
namespace LocalizationManager.Core.Backends.iOS;
@@ -34,7 +35,21 @@ public List<StringsdictEntry> Parse(string content)
3435

3536
try
3637
{
37-
var doc = XDocument.Parse(content);
38+
// Use secure XML settings to prevent XXE attacks
39+
// Note: Use Ignore instead of Prohibit to handle Apple's DOCTYPE declarations
40+
// Ignore still prevents external entity resolution via XmlResolver = null
41+
var settings = new XmlReaderSettings
42+
{
43+
DtdProcessing = DtdProcessing.Ignore,
44+
XmlResolver = null
45+
};
46+
47+
XDocument doc;
48+
using (var reader = XmlReader.Create(new StringReader(content), settings))
49+
{
50+
doc = XDocument.Load(reader);
51+
}
52+
3853
var plist = doc.Element("plist");
3954
var rootDict = plist?.Element("dict");
4055

@@ -88,15 +103,7 @@ public List<StringsdictEntry> Parse(string content)
88103
case "NSStringLocalizedFormatKey":
89104
formatKey = propValue.Value;
90105
// Extract variable name from format like "%#@count@"
91-
if (formatKey.Contains("@"))
92-
{
93-
var start = formatKey.IndexOf('@') + 1;
94-
var end = formatKey.LastIndexOf('@');
95-
if (end > start)
96-
{
97-
variableName = formatKey.Substring(start, end - start);
98-
}
99-
}
106+
variableName = ExtractVariableName(formatKey);
100107
break;
101108

102109
default:

0 commit comments

Comments
 (0)