Skip to content

Commit

Permalink
Fix bug where slashes are part of dictionary words
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 7, 2017
1 parent 321e0c3 commit d35d01b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function add(buf) {
if (compoundCodes[character].length === 0) {
source += character;
} else {
source += '(' + compoundCodes[character].join('|') + ')';
source += '(?:' + compoundCodes[character].join('|') + ')';
}
}

Expand Down
18 changes: 12 additions & 6 deletions lib/util/dictionary.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var own = {}.hasOwnProperty;
var UTF8 = 'utf8';
var C_LINE = '\n';
var C_SLASH = '/';
var C_ESCAPE = '\\';
var CC_TAB = '\t'.charCodeAt(0);

/* Parse a dictionary. */
Expand Down Expand Up @@ -46,14 +47,19 @@ function parse(buf, options, dict) {
while (index !== -1) {
if (value.charCodeAt(last) !== CC_TAB) {
line = value.slice(last, index);
word = line;
codes = [];

offset = line.indexOf(C_SLASH);

if (offset === -1) {
word = line;
codes = [];
} else {
word = line.slice(0, offset);
codes = parseCodes(flags, line.slice(offset + 1));
while (offset !== -1) {
if (line.charAt(offset - 1) !== C_ESCAPE) {
word = line.slice(0, offset);
codes = parseCodes(flags, line.slice(offset + 1));
break;
}

offset = line.indexOf(C_SLASH, offset + 1);
}

/* Compound words. */
Expand Down

0 comments on commit d35d01b

Please sign in to comment.