Skip to content

Commit

Permalink
Ruby: fix str.substring(0, 0) returning str instead of ""
Browse files Browse the repository at this point in the history
See #277 (comment)

The bug fixed here is now tested in the ExprStrOps test, see
kaitai-io/kaitai_struct_tests@b70a99d
  • Loading branch information
generalmimon committed Aug 27, 2024
1 parent 61c2246 commit 37fd633
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 37fd633

Please sign in to comment.