ensure span.text works for an empty span (#6772)

This commit is contained in:
Sofie Van Landeghem 2021-01-21 16:18:46 +01:00 committed by GitHub
parent fdf8c77630
commit 5ace559201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -0,0 +1,9 @@
# coding: utf8
from __future__ import unicode_literals
def test_issue6755(en_tokenizer):
doc = en_tokenizer("This is a magnificent sentence.")
span = doc[:0]
assert span.text_with_ws == ""
assert span.text == ""

View File

@ -500,7 +500,7 @@ cdef class Span:
def text(self):
"""RETURNS (unicode): The original verbatim text of the span."""
text = self.text_with_ws
if self[-1].whitespace_:
if len(self) > 0 and self[-1].whitespace_:
text = text[:-1]
return text