@@ -476,32 +476,32 @@ def format_frame_summary(self, frame_summary):
476476 frame_summary .colno is not None
477477 and frame_summary .end_colno is not None
478478 ):
479- colno = _byte_offset_to_character_offset (
480- frame_summary ._original_line , frame_summary .colno )
481- end_colno = _byte_offset_to_character_offset (
482- frame_summary ._original_line , frame_summary .end_colno )
479+ start_offset = _byte_offset_to_character_offset (
480+ frame_summary ._original_line , frame_summary .colno ) + 1
481+ end_offset = _byte_offset_to_character_offset (
482+ frame_summary ._original_line , frame_summary .end_colno ) + 1
483483
484484 anchors = None
485485 if frame_summary .lineno == frame_summary .end_lineno :
486486 with suppress (Exception ):
487487 anchors = _extract_caret_anchors_from_line_segment (
488- frame_summary ._original_line [colno - 1 :end_colno - 1 ]
488+ frame_summary ._original_line [start_offset - 1 :end_offset - 1 ]
489489 )
490490 else :
491- end_colno = stripped_characters + len (stripped_line )
491+ end_offset = stripped_characters + len (stripped_line )
492492
493493 # show indicators if primary char doesn't span the frame line
494- if end_colno - colno < len (stripped_line ) or (
494+ if end_offset - start_offset < len (stripped_line ) or (
495495 anchors and anchors .right_start_offset - anchors .left_end_offset > 0 ):
496496 row .append (' ' )
497- row .append (' ' * (colno - stripped_characters ))
497+ row .append (' ' * (start_offset - stripped_characters ))
498498
499499 if anchors :
500500 row .append (anchors .primary_char * (anchors .left_end_offset ))
501501 row .append (anchors .secondary_char * (anchors .right_start_offset - anchors .left_end_offset ))
502- row .append (anchors .primary_char * (end_colno - colno - anchors .right_start_offset ))
502+ row .append (anchors .primary_char * (end_offset - start_offset - anchors .right_start_offset ))
503503 else :
504- row .append ('^' * (end_colno - colno ))
504+ row .append ('^' * (end_offset - start_offset ))
505505
506506 row .append ('\n ' )
507507
@@ -561,10 +561,7 @@ def format(self):
561561
562562def _byte_offset_to_character_offset (str , offset ):
563563 as_utf8 = str .encode ('utf-8' )
564- if offset > len (as_utf8 ):
565- offset = len (as_utf8 )
566-
567- return len (as_utf8 [:offset + 1 ].decode ("utf-8" ))
564+ return len (as_utf8 [:offset ].decode ("utf-8" , errors = "replace" ))
568565
569566
570567_Anchors = collections .namedtuple (
0 commit comments