Jelajahi Sumber

Ensure scanner has data before checking for blanks.

Reported as part of #323.

Previously fixed in libyaml with
https://github.com/yaml/libyaml/commit/6bbc217

The fix applied here is slightly simpler, and looks sufficient.
Gustavo Niemeyer 8 tahun lalu
induk
melakukan
3ba0e99ffa
1 mengubah file dengan 4 tambahan dan 4 penghapusan
  1. 4 4
      scannerc.go

+ 4 - 4
scannerc.go

@@ -2469,6 +2469,10 @@ func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, si
 			}
 		}
 
+		if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) {
+			return false
+		}
+
 		// Check if we are at the end of the scalar.
 		if single {
 			if parser.buffer[parser.buffer_pos] == '\'' {
@@ -2481,10 +2485,6 @@ func yaml_parser_scan_flow_scalar(parser *yaml_parser_t, token *yaml_token_t, si
 		}
 
 		// Consume blank characters.
-		if parser.unread < 1 && !yaml_parser_update_buffer(parser, 1) {
-			return false
-		}
-
 		for is_blank(parser.buffer, parser.buffer_pos) || is_break(parser.buffer, parser.buffer_pos) {
 			if is_blank(parser.buffer, parser.buffer_pos) {
 				// Consume a space or a tab character.