浏览代码

[GDScript] Check string literals for Unicode direction control characters.

bruvzg 3 年之前
父节点
当前提交
74b9892f7a
共有 1 个文件被更改,包括 9 次插入0 次删除
  1. 9 0
      modules/gdscript/gdscript_tokenizer.cpp

+ 9 - 0
modules/gdscript/gdscript_tokenizer.cpp

@@ -795,6 +795,15 @@ GDScriptTokenizer::Token GDScriptTokenizer::string() {
 
 		char32_t ch = _peek();
 
+		if (ch == 0x200E || ch == 0x200F || (ch >= 0x202A && ch <= 0x202E) || (ch >= 0x2066 && ch <= 0x2069)) {
+			Token error = make_error("Invisible text direction control character present in the string, escape it (\"\\u" + String::num_int64(ch, 16) + "\") to avoid confusion.");
+			error.start_column = column;
+			error.leftmost_column = error.start_column;
+			error.end_column = column + 1;
+			error.rightmost_column = error.end_column;
+			push_error(error);
+		}
+
 		if (ch == '\\') {
 			// Escape pattern.
 			_advance();