Fix text content of Linkify ranges, add test.

This commit is contained in:
ccd0 2014-12-07 03:24:11 -08:00
parent 5c327555d5
commit b16e2205ed
2 changed files with 13 additions and 4 deletions

View File

@ -25,6 +25,10 @@ module.exports = (grunt) ->
output = if parts2.length is 0 then '""' else parts2.join ' + '
"(innerHTML: #{output})"
assert = (statement, objs...) ->
return '' unless grunt.config('pkg').tests_enabled
"throw new Error 'Assertion failed: ' + `#{JSON.stringify statement}` unless #{statement}"
# Project configuration.
grunt.initConfig
pkg: grunt.file.readJSON 'package.json'
@ -35,6 +39,7 @@ module.exports = (grunt) ->
pkg = grunt.config 'pkg'
pkg.importHTML = importHTML
pkg.html = html
pkg.assert = assert
pkg.tests_enabled or= false
pkg
enumerable: true

View File

@ -52,16 +52,20 @@ Linkify =
endNode = saved
{data} = saved
word += data
{length} = data
if end = space.exec data
# Set our snapshot and regex to start on this node at this position when the loop resumes
word += data[...end.index]
test.lastIndex = length = end.index
i--
break
else
{length} = data
word += data
links.push Linkify.makeRange node, endNode, index, length if Linkify.regString.exec word
if Linkify.regString.exec word
links.push Linkify.makeRange node, endNode, index, length
<%= assert('word is links[links.length-1].toString()') %>
break unless test.lastIndex and node is endNode
@ -105,7 +109,7 @@ Linkify =
# Clean start of range
i = text.search Linkify.regString
if i
if i > 0
text = text.slice i
i-- while range.startOffset + i >= range.startContainer.data.length