From 84816a2a30a84c9722355eaac432ecae4f455759 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 7 Mar 2014 15:02:00 -0500 Subject: [PATCH] stdlib/strings: Fixed behaviour for substring_from, returns an empty string instead of crashing when from < 0. Signed-off-by: Lucas Bajolet --- lib/standard/string.nit | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/standard/string.nit b/lib/standard/string.nit index d416000..cbd6c09 100644 --- a/lib/standard/string.nit +++ b/lib/standard/string.nit @@ -169,7 +169,8 @@ abstract class Text # As with substring, a `from` index < 0 will be replaced by 0 fun substring_from(from: Int): SELFTYPE do - assert from < length + if from > self.length then return empty + if from < 0 then from = 0 return substring(from, length - from) end -- 1.7.9.5