[前][次][番号順一覧][スレッド一覧]

ruby-changes:72741

From: Jean <ko1@a...>
Date: Fri, 29 Jul 2022 19:10:25 +0900 (JST)
Subject: [ruby-changes:72741] 66b52f046f (master): [flori/json] Stop including the parser source __LINE__ in exceptions

https://git.ruby-lang.org/ruby.git/commit/?id=66b52f046f

From 66b52f046f3e4c5d24781a142f9633e07c42d6d9 Mon Sep 17 00:00:00 2001
From: Jean Boussier <jean.boussier@g...>
Date: Thu, 20 May 2021 12:40:04 +0200
Subject: [flori/json] Stop including the parser source __LINE__ in exceptions

It makes testing for JSON errors very tedious. You either have
to use a Regexp or to regularly update all your assertions
when JSON is upgraded.

https://github.com/flori/json/commit/de9eb1d28e
---
 ext/json/generator/generator.c |  4 ++--
 ext/json/parser/parser.c       | 14 +++++++-------
 ext/json/parser/parser.rl      | 14 +++++++-------
 3 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index e3a83472e1..98d0ea46c3 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -997,10 +997,10 @@ static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_St https://github.com/ruby/ruby/blob/trunk/ext/json/generator/generator.c#L997
     if (!allow_nan) {
         if (isinf(value)) {
             fbuffer_free(buffer);
-            rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
+            rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
         } else if (isnan(value)) {
             fbuffer_free(buffer);
-            rb_raise(eGeneratorError, "%u: %"PRIsVALUE" not allowed in JSON", __LINE__, RB_OBJ_STRING(tmp));
+            rb_raise(eGeneratorError, "%"PRIsVALUE" not allowed in JSON", RB_OBJ_STRING(tmp));
         }
     }
     fbuffer_append_str(buffer, tmp);
diff --git a/ext/json/parser/parser.c b/ext/json/parser/parser.c
index 8b860c4101..9bd7f1971e 100644
--- a/ext/json/parser/parser.c
+++ b/ext/json/parser/parser.c
@@ -948,7 +948,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L948
 
 					{p = p - 1; } {p+= 1; cs = 29; goto _out;}
 				} else {
-					rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+					rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
 				}
 			}
 			np = JSON_parse_float(json, p, pe, result);
@@ -990,7 +990,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L990
 			if (json->allow_nan) {
 				*result = CInfinity;
 			} else {
-				rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+				rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 8);
 			}
 		}
 
@@ -1002,7 +1002,7 @@ static char *JSON_parse_value(JSON_Parser *json, char *p, char *pe, VALUE *resul https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L1002
 			if (json->allow_nan) {
 				*result = CNaN;
 			} else {
-				rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+				rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
 			}
 		}
 
@@ -2348,7 +2348,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2348
 	if(cs >= JSON_array_first_final) {
 		return p + 1;
 	} else {
-		rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+		rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
 		return NULL;
 	}
 }
@@ -2413,7 +2413,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2413
 					}
 					rb_enc_raise(
 					EXC_ENCODING eParserError,
-					"%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
+					"incomplete unicode character escape sequence at '%s'", p
 					);
 				} else {
 					UTF32 ch = unescape_unicode((unsigned char *) ++pe);
@@ -2426,7 +2426,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L2426
 							}
 							rb_enc_raise(
 							EXC_ENCODING eParserError,
-							"%u: incomplete surrogate pair at '%s'", __LINE__, p
+							"incomplete surrogate pair at '%s'", p
 							);
 						}
 						if (pe[0] == '\\' && pe[1] == 'u') {
@@ -3225,7 +3225,7 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.c#L3225
 	if (cs >= JSON_first_final && p == pe) {
 		return result;
 	} else {
-		rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+		rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
 		return Qnil;
 	}
 }
diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl
index 2dee80ee3b..2dbdc7ef24 100644
--- a/ext/json/parser/parser.rl
+++ b/ext/json/parser/parser.rl
@@ -222,14 +222,14 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L222
         if (json->allow_nan) {
             *result = CNaN;
         } else {
-            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 2);
+            rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 2);
         }
     }
     action parse_infinity {
         if (json->allow_nan) {
             *result = CInfinity;
         } else {
-            rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p - 8);
+            rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p - 8);
         }
     }
     action parse_string {
@@ -245,7 +245,7 @@ static char *JSON_parse_object(JSON_Parser *json, char *p, char *pe, VALUE *resu https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L245
                 fexec p + 10;
                 fhold; fbreak;
             } else {
-                rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+                rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
             }
         }
         np = JSON_parse_float(json, fpc, pe, result);
@@ -447,7 +447,7 @@ static char *JSON_parse_array(JSON_Parser *json, char *p, char *pe, VALUE *resul https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L447
     if(cs >= JSON_array_first_final) {
         return p + 1;
     } else {
-        rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+        rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
         return NULL;
     }
 }
@@ -512,7 +512,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L512
                       }
                       rb_enc_raise(
                         EXC_ENCODING eParserError,
-                        "%u: incomplete unicode character escape sequence at '%s'", __LINE__, p
+                        "incomplete unicode character escape sequence at '%s'", p
                       );
                     } else {
                         UTF32 ch = unescape_unicode((unsigned char *) ++pe);
@@ -525,7 +525,7 @@ static VALUE json_string_unescape(char *string, char *stringEnd, int intern, int https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L525
                               }
                               rb_enc_raise(
                                 EXC_ENCODING eParserError,
-                                "%u: incomplete surrogate pair at '%s'", __LINE__, p
+                                "incomplete surrogate pair at '%s'", p
                                 );
                             }
                             if (pe[0] == '\\' && pe[1] == 'u') {
@@ -864,7 +864,7 @@ static VALUE cParser_parse(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/json/parser/parser.rl#L864
   if (cs >= JSON_first_final && p == pe) {
     return result;
   } else {
-    rb_enc_raise(EXC_ENCODING eParserError, "%u: unexpected token at '%s'", __LINE__, p);
+    rb_enc_raise(EXC_ENCODING eParserError, "unexpected token at '%s'", p);
     return Qnil;
   }
 }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]