From 37fd6335e242b3286f228c304c34759f561438c9 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 27 Aug 2024 15:00:28 +0200 Subject: [PATCH] Ruby: fix `str.substring(0, 0)` returning `str` instead of `""` See https://github.com/kaitai-io/kaitai_struct_compiler/pull/277#issuecomment-2000631416 The bug fixed here is now tested in the ExprStrOps test, see https://github.com/kaitai-io/kaitai_struct_tests/commit/b70a99d66afc8bd88de95d20685549c7d444f66e --- .../scala/io/kaitai/struct/translators/RubyTranslator.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/src/main/scala/io/kaitai/struct/translators/RubyTranslator.scala b/shared/src/main/scala/io/kaitai/struct/translators/RubyTranslator.scala index d89b28153..8018430dc 100644 --- a/shared/src/main/scala/io/kaitai/struct/translators/RubyTranslator.scala +++ b/shared/src/main/scala/io/kaitai/struct/translators/RubyTranslator.scala @@ -121,7 +121,7 @@ class RubyTranslator(provider: TypeProvider) extends BaseTranslator(provider) override def strReverse(s: Ast.expr): String = s"${translate(s, METHOD_PRECEDENCE)}.reverse" override def strSubstring(s: Ast.expr, from: Ast.expr, to: Ast.expr): String = - s"${translate(s, METHOD_PRECEDENCE)}[${translate(from)}..${genericBinOp(to, Ast.operator.Sub, Ast.expr.IntNum(1), 0)}]" + s"${translate(s, METHOD_PRECEDENCE)}[${translate(from)}...${translate(to)}]" override def arrayFirst(a: Ast.expr): String = s"${translate(a, METHOD_PRECEDENCE)}.first"