Skip to content
This repository has been archived by the owner on Sep 7, 2024. It is now read-only.

Handle single quotes in attr regex #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function truncate(string, maxLength, options) {
items = [], // stack for saving tags
total = 0, // record how many characters we traced so far
content = EMPTY_STRING, // truncated text storage
KEY_VALUE_REGEX = '([\\w|-]+\\s*=\\s*"[^"]*"\\s*)*',
KEY_VALUE_REGEX = '([\\w|-]+\\s*=\\s*["\'][^"]*["\']\\s*)*',
IS_CLOSE_REGEX = '\\s*\\/?\\s*',
CLOSE_REGEX = '\\s*\\/\\s*',
SELF_CLOSE_REGEX = new RegExp('<\\/?\\w+\\s*' + KEY_VALUE_REGEX + CLOSE_REGEX + '>'),
Expand Down
10 changes: 10 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,14 @@ describe('truncate', function() {
expect = 'thisare19characters <a href="http://google.com">http://google...</a>';
assert.strictEqual(expect, actual);
});

it('should handle single quotes in attributes', function() {
var input, expect, actual;

input = "hello <a href='http://google.com'>world</a>";
actual = truncate(input, 8);
expect = "hello <a href='http://google.com'>wo...</a>";
assert.strictEqual(expect, actual);
});

});