Skip to content

Commit 86d26cb

Browse files
committed
Fix exception on sentence followed by EOF
Closes GH-2.
1 parent 4cc839d commit 86d26cb

File tree

2 files changed

+35
-9
lines changed

2 files changed

+35
-9
lines changed

index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ export default function retextSyntaxUrls() {
8383
// Find following word/punctuation.
8484
let next = siblings[end + 1]
8585
while (
86-
next.type === 'WordNode' ||
87-
next.type === 'PunctuationNode' ||
88-
next.type === 'SymbolNode'
86+
next &&
87+
(next.type === 'WordNode' ||
88+
next.type === 'PunctuationNode' ||
89+
next.type === 'SymbolNode')
8990
) {
9091
end++
9192
nodes.push(next)

test/index.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ const noPosition = retext()
2424
.use(retextSyntaxUrls)
2525

2626
test('retext-syntax-urls', (t) => {
27-
t.test('Correct URLs', (st) => {
27+
t.test('Correct URLs', (t) => {
2828
let index = -1
2929
while (++index < correct.length) {
3030
const url = correct[index]
31-
st.doesNotThrow(() => {
31+
t.doesNotThrow(() => {
3232
const tree = position.parse('Check out ' + url + ' it’s awesome!')
3333
/** @type {Source} */
3434
// @ts-expect-error: fine.
@@ -38,15 +38,15 @@ test('retext-syntax-urls', (t) => {
3838
}, url)
3939
}
4040

41-
st.end()
41+
t.end()
4242
})
4343

44-
t.test('Incorrect URLs', (st) => {
44+
t.test('Incorrect URLs', (t) => {
4545
let index = -1
4646
while (++index < incorrect.length) {
4747
const url = incorrect[index]
4848

49-
st.doesNotThrow(() => {
49+
t.doesNotThrow(() => {
5050
const tree = position.parse('Check out ' + url + ' it’s bad!')
5151

5252
visit(tree, 'SourceNode', (node) => {
@@ -55,9 +55,34 @@ test('retext-syntax-urls', (t) => {
5555
}, url)
5656
}
5757

58-
st.end()
58+
t.end()
5959
})
6060

61+
t.deepEqual(
62+
noPosition.parse('More.'),
63+
{
64+
type: 'RootNode',
65+
children: [
66+
{
67+
type: 'ParagraphNode',
68+
children: [
69+
{
70+
type: 'SentenceNode',
71+
children: [
72+
{
73+
type: 'WordNode',
74+
children: [{type: 'TextNode', value: 'More'}]
75+
},
76+
{type: 'PunctuationNode', value: '.'}
77+
]
78+
}
79+
]
80+
}
81+
]
82+
},
83+
'should support a sentence followed by eof'
84+
)
85+
6186
t.end()
6287
})
6388

0 commit comments

Comments
 (0)