[Cuis-dev] Possible bugfix: #printStringLimitedTo: goes 4 characters over its limit whenever it truncates

Facundo Javier Gelatti javiergelatti at gmail.com
Sun Oct 4 12:23:50 PDT 2026


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20261004/3a77b755/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KernelTests-Object_printAs_limitedTo.cs.st
Type: application/vnd.sailingtracker.track
Size: 971 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20261004/3a77b755/attachment.st>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CuisCore-Object_printAs_limitedTo.cs.st
Type: application/vnd.sailingtracker.track
Size: 1471 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20261004/3a77b755/attachment-0001.st>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CuisCore-printStringLimitedTo_sendersLeaveRoomForMarker.cs.st
Type: application/vnd.sailingtracker.track
Size: 1291 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20261004/3a77b755/attachment-0002.st>


More information about the Cuis-dev mailing list