@@ -475,32 +475,32 @@ def format_frame_summary(self, frame_summary):
475475 frame_summary .colno is not None
476476 and frame_summary .end_colno is not None
477477 ):
478- colno = _byte_offset_to_character_offset (
479- frame_summary ._original_line , frame_summary .colno )
480- end_colno = _byte_offset_to_character_offset (
481- frame_summary ._original_line , frame_summary .end_colno )
478+ start_offset = _byte_offset_to_character_offset (
479+ frame_summary ._original_line , frame_summary .colno ) + 1
480+ end_offset = _byte_offset_to_character_offset (
481+ frame_summary ._original_line , frame_summary .end_colno ) + 1
482482
483483 anchors = None
484484 if frame_summary .lineno == frame_summary .end_lineno :
485485 with suppress (Exception ):
486486 anchors = _extract_caret_anchors_from_line_segment (
487- frame_summary ._original_line [colno - 1 :end_colno - 1 ]
487+ frame_summary ._original_line [start_offset - 1 :end_offset - 1 ]
488488 )
489489 else :
490- end_colno = stripped_characters + len (stripped_line )
490+ end_offset = stripped_characters + len (stripped_line )
491491
492492 # show indicators if primary char doesn't span the frame line
493- if end_colno - colno < len (stripped_line ) or (
493+ if end_offset - start_offset < len (stripped_line ) or (
494494 anchors and anchors .right_start_offset - anchors .left_end_offset > 0 ):
495495 row .append (' ' )
496- row .append (' ' * (colno - stripped_characters ))
496+ row .append (' ' * (start_offset - stripped_characters ))
497497
498498 if anchors :
499499 row .append (anchors .primary_char * (anchors .left_end_offset ))
500500 row .append (anchors .secondary_char * (anchors .right_start_offset - anchors .left_end_offset ))
501- row .append (anchors .primary_char * (end_colno - colno - anchors .right_start_offset ))
501+ row .append (anchors .primary_char * (end_offset - start_offset - anchors .right_start_offset ))
502502 else :
503- row .append ('^' * (end_colno - colno ))
503+ row .append ('^' * (end_offset - start_offset ))
504504
505505 row .append ('\n ' )
506506
@@ -560,10 +560,7 @@ def format(self):
560560
561561def _byte_offset_to_character_offset (str , offset ):
562562 as_utf8 = str .encode ('utf-8' )
563- if offset > len (as_utf8 ):
564- offset = len (as_utf8 )
565-
566- return len (as_utf8 [:offset + 1 ].decode ("utf-8" ))
563+ return len (as_utf8 [:offset ].decode ("utf-8" , errors = "replace" ))
567564
568565
569566_Anchors = collections .namedtuple (
0 commit comments