From 10fa40d9a9b3b2af8873e812347e6df3b9d74971 Mon Sep 17 00:00:00 2001 From: Martin Finkel Date: Mon, 31 Aug 2020 18:18:53 +0200 Subject: [PATCH] =?UTF-8?q?=C3=81dd=20additional=20check=20for=20invalid?= =?UTF-8?q?=20character=20in=20property?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Build.UnitTests/Scanner_Tests.cs | 19 +++++++++++ src/Build/Evaluation/Conditionals/Scanner.cs | 35 ++++++++++++-------- src/Build/Resources/Strings.resx | 4 +++ src/Build/Resources/xlf/Strings.cs.xlf | 5 +++ src/Build/Resources/xlf/Strings.de.xlf | 5 +++ src/Build/Resources/xlf/Strings.en.xlf | 5 +++ src/Build/Resources/xlf/Strings.es.xlf | 5 +++ src/Build/Resources/xlf/Strings.fr.xlf | 5 +++ src/Build/Resources/xlf/Strings.it.xlf | 5 +++ src/Build/Resources/xlf/Strings.ja.xlf | 5 +++ src/Build/Resources/xlf/Strings.ko.xlf | 5 +++ src/Build/Resources/xlf/Strings.pl.xlf | 5 +++ src/Build/Resources/xlf/Strings.pt-BR.xlf | 5 +++ src/Build/Resources/xlf/Strings.ru.xlf | 5 +++ src/Build/Resources/xlf/Strings.tr.xlf | 5 +++ src/Build/Resources/xlf/Strings.zh-Hans.xlf | 5 +++ src/Build/Resources/xlf/Strings.zh-Hant.xlf | 5 +++ 17 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/Build.UnitTests/Scanner_Tests.cs b/src/Build.UnitTests/Scanner_Tests.cs index 0903dedcaeb..b952974f39f 100644 --- a/src/Build.UnitTests/Scanner_Tests.cs +++ b/src/Build.UnitTests/Scanner_Tests.cs @@ -115,6 +115,25 @@ public void WhitespaceProperty() Assert.Equal("IllFormedPropertyWhitespaceInCondition", lexer.GetErrorResource()); } + /// + /// Tests for invalid element in property + /// + [Fact] + public void IllFormedPropertyInvalidElement() + { + Scanner lexer = new Scanner("$(x\\)", ParserOptions.AllowProperties); + AdvanceToScannerError(lexer); + Assert.Equal("IllFormedPropertyInvalidElementInCondition", lexer.GetErrorResource()); + + lexer = new Scanner("$(x{)", ParserOptions.AllowProperties); + AdvanceToScannerError(lexer); + Assert.Equal("IllFormedPropertyInvalidElementInCondition", lexer.GetErrorResource()); + + lexer = new Scanner("$(x;)", ParserOptions.AllowProperties); + AdvanceToScannerError(lexer); + Assert.Equal("IllFormedPropertyInvalidElementInCondition", lexer.GetErrorResource()); + } + /// /// Tests the special errors for "@(" and "@x" and similar cases. /// diff --git a/src/Build/Evaluation/Conditionals/Scanner.cs b/src/Build/Evaluation/Conditionals/Scanner.cs index 83a99f238d7..3e7ef254f6b 100644 --- a/src/Build/Evaluation/Conditionals/Scanner.cs +++ b/src/Build/Evaluation/Conditionals/Scanner.cs @@ -283,12 +283,12 @@ private string ParsePropertyOrItemMetadata() return null; } - var result = ScanForPropertyExpressionEnd(_expression, _parsePoint++, out int indexResult); - if (!result) + var errorMessage = ScanForPropertyExpressionEnd(_expression, _parsePoint++, out int indexResult); + if (!string.IsNullOrEmpty(errorMessage)) { _errorState = true; _errorPosition = indexResult; - _errorResource = "IllFormedPropertyWhitespaceInCondition"; + _errorResource = errorMessage; _unexpectedlyFound = Convert.ToString(_expression[indexResult], CultureInfo.InvariantCulture); return null; } @@ -316,11 +316,12 @@ private string ParsePropertyOrItemMetadata() /// current index to start from /// If successful, the index corresponds to the end of the property expression. /// In case of scan failure, it is the error position index. - /// result indicating whether or not the scan was successful. - private static bool ScanForPropertyExpressionEnd(string expression, int index, out int indexResult) + /// Empty string in case of success, specific error message otherwise + private static string ScanForPropertyExpressionEnd(string expression, int index, out int indexResult) { int nestLevel = 0; - bool whitespaceCheck = false; + bool propertyValue = false; + string errorMessage = string.Empty; unsafe { @@ -332,17 +333,25 @@ private static bool ScanForPropertyExpressionEnd(string expression, int index, o if (character == '(') { nestLevel++; - whitespaceCheck = true; + propertyValue = true; } else if (character == ')') { nestLevel--; - whitespaceCheck = false; + propertyValue = false; } - else if (whitespaceCheck && char.IsWhiteSpace(character)) + else if (propertyValue) { - indexResult = index; - return false; + if (char.IsWhiteSpace(character)) + { + indexResult = index; + return "IllFormedPropertyWhitespaceInCondition"; + } + else if (!XmlUtilities.IsValidSubsequentElementNameCharacter(character)) + { + indexResult = index; + return "IllFormedPropertyInvalidElementInCondition"; + } } // We have reached the end of the parenthesis nesting @@ -351,7 +360,7 @@ private static bool ScanForPropertyExpressionEnd(string expression, int index, o if (nestLevel == 0) { indexResult = index; - return true; + return errorMessage; } else { @@ -361,7 +370,7 @@ private static bool ScanForPropertyExpressionEnd(string expression, int index, o } } indexResult = index; - return true; + return errorMessage; } /// diff --git a/src/Build/Resources/Strings.resx b/src/Build/Resources/Strings.resx index 9188ff9e572..9cf46b3a537 100644 --- a/src/Build/Resources/Strings.resx +++ b/src/Build/Resources/Strings.resx @@ -482,6 +482,10 @@ MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? {StrBegin="MSB4151: "} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4101: Expected a closing quote after position {1} in condition "{0}". {StrBegin="MSB4101: "} diff --git a/src/Build/Resources/xlf/Strings.cs.xlf b/src/Build/Resources/xlf/Strings.cs.xlf index faa2b6ec62d..4ab2316f49a 100644 --- a/src/Build/Resources/xlf/Strings.cs.xlf +++ b/src/Build/Resources/xlf/Strings.cs.xlf @@ -90,6 +90,11 @@ MSB4258: Při zápisu do výstupních souborů mezipaměti pro výsledky v cestě {0} byla zjištěna chyba: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.de.xlf b/src/Build/Resources/xlf/Strings.de.xlf index eb9dd9fb3d6..24edfd28f9b 100644 --- a/src/Build/Resources/xlf/Strings.de.xlf +++ b/src/Build/Resources/xlf/Strings.de.xlf @@ -90,6 +90,11 @@ MSB4258: Beim Schreiben der Cachedatei für Ausgabeergebnisse im Pfad "{0}" wurde ein Fehler festgestellt: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.en.xlf b/src/Build/Resources/xlf/Strings.en.xlf index 2e7887576c3..678746f8fc7 100644 --- a/src/Build/Resources/xlf/Strings.en.xlf +++ b/src/Build/Resources/xlf/Strings.en.xlf @@ -90,6 +90,11 @@ MSB4258: Writing output result cache file in path "{0}" encountered an error: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.es.xlf b/src/Build/Resources/xlf/Strings.es.xlf index dc6b6074ae4..f89fef3d66b 100644 --- a/src/Build/Resources/xlf/Strings.es.xlf +++ b/src/Build/Resources/xlf/Strings.es.xlf @@ -90,6 +90,11 @@ MSB4258: Error al escribir el archivo de caché de resultados de salida en la ruta de acceso "{0}": {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.fr.xlf b/src/Build/Resources/xlf/Strings.fr.xlf index a7c615aeff6..fc8d466f405 100644 --- a/src/Build/Resources/xlf/Strings.fr.xlf +++ b/src/Build/Resources/xlf/Strings.fr.xlf @@ -90,6 +90,11 @@ MSB4258: L'écriture du fichier cache des résultats de sortie dans le chemin "{0}" a rencontré une erreur : {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.it.xlf b/src/Build/Resources/xlf/Strings.it.xlf index 204530b28c1..664f83c7eed 100644 --- a/src/Build/Resources/xlf/Strings.it.xlf +++ b/src/Build/Resources/xlf/Strings.it.xlf @@ -90,6 +90,11 @@ MSB4258: durante la scrittura del file della cache dei risultati di output nel percorso "{0}" è stato rilevato un errore: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.ja.xlf b/src/Build/Resources/xlf/Strings.ja.xlf index 6adec782fcc..0effa09a84d 100644 --- a/src/Build/Resources/xlf/Strings.ja.xlf +++ b/src/Build/Resources/xlf/Strings.ja.xlf @@ -90,6 +90,11 @@ MSB4258: パス "{0}" の出力結果キャッシュ ファイルに書き込む処理でエラーが発生しました: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.ko.xlf b/src/Build/Resources/xlf/Strings.ko.xlf index f87cc7c8e26..476a6e2d636 100644 --- a/src/Build/Resources/xlf/Strings.ko.xlf +++ b/src/Build/Resources/xlf/Strings.ko.xlf @@ -90,6 +90,11 @@ MSB4258: "{0}" 경로에서 출력 결과 캐시 파일을 쓰는 중 오류가 발생했습니다. {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.pl.xlf b/src/Build/Resources/xlf/Strings.pl.xlf index 3b2a7e2080f..7a05128d903 100644 --- a/src/Build/Resources/xlf/Strings.pl.xlf +++ b/src/Build/Resources/xlf/Strings.pl.xlf @@ -90,6 +90,11 @@ MSB4258: Podczas zapisywania pliku wyjściowej pamięci podręcznej wyników w ścieżce „{0}” wystąpił błąd: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.pt-BR.xlf b/src/Build/Resources/xlf/Strings.pt-BR.xlf index 917647996bf..5a9afe55a17 100644 --- a/src/Build/Resources/xlf/Strings.pt-BR.xlf +++ b/src/Build/Resources/xlf/Strings.pt-BR.xlf @@ -90,6 +90,11 @@ MSB4258: a gravação do arquivo de cache do resultado de saída no caminho "{0}" encontrou um erro: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.ru.xlf b/src/Build/Resources/xlf/Strings.ru.xlf index 57b62004fa3..b57a830b5e1 100644 --- a/src/Build/Resources/xlf/Strings.ru.xlf +++ b/src/Build/Resources/xlf/Strings.ru.xlf @@ -90,6 +90,11 @@ MSB4258: произошла ошибка при записи выходного файла кэша результатов в пути "{0}": {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.tr.xlf b/src/Build/Resources/xlf/Strings.tr.xlf index 4bc4d48aceb..04fb347db2c 100644 --- a/src/Build/Resources/xlf/Strings.tr.xlf +++ b/src/Build/Resources/xlf/Strings.tr.xlf @@ -90,6 +90,11 @@ MSB4258: Çıkış sonucu önbellek dosyası "{0}" yoluna yazılırken bir hatayla karşılaşıldı: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.zh-Hans.xlf b/src/Build/Resources/xlf/Strings.zh-Hans.xlf index 3a47acf8311..36380eb8a2a 100644 --- a/src/Build/Resources/xlf/Strings.zh-Hans.xlf +++ b/src/Build/Resources/xlf/Strings.zh-Hans.xlf @@ -90,6 +90,11 @@ MSB4258: 从路径“{0}”写入输出结果缓存文件时遇到错误: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? diff --git a/src/Build/Resources/xlf/Strings.zh-Hant.xlf b/src/Build/Resources/xlf/Strings.zh-Hant.xlf index 43ca934755f..e95efefdf3f 100644 --- a/src/Build/Resources/xlf/Strings.zh-Hant.xlf +++ b/src/Build/Resources/xlf/Strings.zh-Hant.xlf @@ -90,6 +90,11 @@ MSB4258: 在路徑 "{0}" 中寫入輸出結果快取檔案發生錯誤: {1} + + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + MSB4152: Unexpected invalid element at position "{1}" of condition "{0}". + {StrBegin="MSB4152: "} + MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace? MSB4151: Unexpected whitespace at position "{1}" of condition "{0}". Did you forget to remove a whitespace?