[Cuis-dev] Possible bugfix: #printStringLimitedTo: goes 4 characters over its limit whenever it truncates
Juan Vuletich
juan at cuis.st
Mon Oct 5 13:38:58 PDT 2026
Nice!
This is now at GitHub.
Thanks,
On 2026-10-04 4:23 PM, Facundo Javier Gelatti via Cuis-dev wrote:
> Hello!
>
> While working on the last bugfix, I've noticed that
> Object>>printAs:limitedTo: (which is used by #printString and
> #printStringLimitedTo:) answers 4 characters more than its limit
> whenever it has to truncate the string.
>
> For example, with Object new (whose print string is 'an Object', 9
> characters):
> Object new printStringLimitedTo: 5 " => 'an Ob[..]' (size 9)"
> Object new printStringLimitedTo: 9 " => 'an Object[..]' (size 13)"
>
> I don't know if this is the expected behavior, but I've found it a bit
> weird. I think there are two problems in the current implementation:
> 1. When the string is truncated, it just appends the '[..]' marker on
> top of the limit, so every truncated result is 4 characters over the
> limit.
> 2. It compares with #< instead of #<=, so a description that fits the
> limit exactly is truncated and gets the marker too (like in the second
> example above).
>
> So, I attach three change sets:
>
> * KernelTests-Object_printAs_limitedTo incudes two new tests in
> ObjectTest that reproduce the problematic cases.
> * CuisCore-Object_printAs_limitedTo contains the fix to
> Object>>printAs:limitedTo:, and the same fix in
> BreakingMethodWrapper>>printAs:limitedTo: (the wrapper is a
> ProtoObject subclass with its own copy of the method).
> * CuisCore-printStringLimitedTo_sendersLeaveRoomForMarker is a small
> change to two senders that calculate the limit using a floor of 1.
> With the old code, a truncated string showed one character plus
> the marker. But with the new code it would show just the marker,
> so I raised the floor to 5 (so it works as before, since the
> marker has size 4).
>
> I wasn't sure what the expected behavior was, so I went to what I
> thought could be reasonable, or at least be an improvement to what we
> already have.
>
> Cheers!
> Facu
>
--
Juan Vuletich
www.cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20261005/5a4fd7d7/attachment.htm>
More information about the Cuis-dev
mailing list