Artifacts Associated With Ticket 3e7c4a039d
Ticket change [4988a3b3af] (rid 260427) by serhiy.storchaka on 2026-10-25 11:56:01:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
<tt>tcl_startOfPreviousWord</tt> returns a wrong result when <tt>start</tt> is equal to (or greater than) the length of the string and the last word has one character: <verbatim> % tcl_startOfPreviousWord {a b c} 5 2 % tcl_startOfPreviousWord {ab c} 4 0 </verbatim> The expected results are 4 and 3, which 8.5 and 8.6.13 return. The last character is dropped, so the last word is not found when it has one character. For longer words the result happens to be right (word-2.6). This is a regression from the fix for [16e25e1402] ([8f65470f72], 8.6.14): <tt>[string range [string range $str 0 $start] 0 end-1]</tt> drops the last character also when <tt>$start</tt> is beyond the end of the string, while the old <tt>[string range $str 0 $start-1]</tt> did not. It affects Tk: in an entry or spinbox using these procedures (8.6, or <tt>-locale tcl8</tt> in 9.x), Ctrl+Left from the end of the text skips a final one-character word. A possible fix that keeps <tt>end-1</tt> working: <verbatim> set prefix [string range $str 0 $start] if {[string index $str $start] ne ""} { set prefix [string range $prefix 0 end-1] } regexp -indices -- $WordBreakRE(previous) $prefix result word </verbatim> with tests such as <tt>tcl_startOfPreviousWord "ab c" 4</tt> → 3 and <tt>tcl_startOfPreviousWord "ab c" end+1</tt> → 3. With it, all word-2.* cases still give the same results (checked with 8.6.18 and 9.1.1 by redefining the procedure). - foundin initialized to: "8.6.14, 9.0.5, 9.1.1"
- login: "serhiy.storchaka"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "serhiy.storchaka"
- subsystem initialized to: "69. Other"
- title initialized to:
tcl_startOfPreviousWord ignores the last character when start is the string length
- type initialized to: "Bug"
Ticket change [0b307ec870] (rid 260433) by serhiy.storchaka on 2026-10-25 12:03:56:
- icomment:
Proposed fix in branch [/timeline?r=word-previous-last-char|word-previous-last-char] (the change suggested above), with tests word-2.10..2.14.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [c4c8b218e3] (rid 260479) by jan.nijtmans on 2026-10-26 14:04:11:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2461340.0862499652"
- closer changed to: "jan.nijtmans"
- comment changed to:
<tt>tcl_startOfPreviousWord</tt> returns a wrong result when <tt>start</tt> is equal to (or greater than) the length of the string and the last word has one character: <verbatim> % tcl_startOfPreviousWord {a b c} 5 2 % tcl_startOfPreviousWord {ab c} 4 0 </verbatim> The expected results are 4 and 3, which 8.5 and 8.6.13 return. The last character is dropped, so the last word is not found when it has one character. For longer words the result happens to be right (word-2.6). This is a regression from the fix for [16e25e1402] ([8f65470f72], 8.6.14): <tt>[string range [string range $str 0 $start] 0 end-1]</tt> drops the last character also when <tt>$start</tt> is beyond the end of the string, while the old <tt>[string range $str 0 $start-1]</tt> did not. It affects Tk: in an entry or spinbox using these procedures (8.6, or <tt>-locale tcl8</tt> in 9.x), Ctrl+Left from the end of the text skips a final one-character word. A possible fix that keeps <tt>end-1</tt> working: <verbatim> set prefix [string range $str 0 $start] if {[string index $str $start] ne ""} { set prefix [string range $prefix 0 end-1] } regexp -indices -- $WordBreakRE(previous) $prefix result word </verbatim> with tests such as <tt>tcl_startOfPreviousWord "ab c" 4</tt> → 3 and <tt>tcl_startOfPreviousWord "ab c" end+1</tt> → 3. With it, all word-2.* cases still give the same results (checked with 8.6.18 and 9.1.1 by redefining the procedure). - icomment:
Fix merged to [c79e0372a7|trunk], core-9-0-branch and core-8-6-branch Many thanks!
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"