Skip to content

Commit

Permalink
Merge pull request #25 from leftstick/master
Browse files Browse the repository at this point in the history
handle space-separated domain
  • Loading branch information
feross committed Dec 27, 2016
2 parents d01d1c9 + abce631 commit c09bb3b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#npm
node_modules/
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ exports.getFile = function (filePath, preserveFormatting, cb) {
function online (line) {
// Remove all comment text from the line
var lineSansComments = line.replace(/#.*/, '')
var matches = /^\s*?(.+?)\s+(\S+?)\s*$/.exec(lineSansComments)
var matches = /^\s*?(.+?)\s+(.+)\s*$/.exec(lineSansComments)
if (matches && matches.length === 3) {
// Found a hosts entry
var ip = matches[1]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hostile",
"description": "Simple /etc/hosts manipulation",
"version": "1.1.1",
"version": "1.1.2",
"author": "Feross Aboukhadijeh <feross@feross.org> (http://feross.org/)",
"bin": {
"hostile": "bin/cmd.js"
Expand Down
17 changes: 17 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,20 @@ test('remove', function (t) {
})
})
})

test('space-separated domains', function (t) {
t.plan(2)
hostile.set('127.0.0.5', 'www.peercdn.com m.peercdn.com', function (err) {
t.error(err)
hostile.get(false, function (err, lines) {
t.error(err)
var finds = lines.filter(function (line) {
return line[0] === '127.0.0.5' && line[1] === 'www.peercdn.com m.peercdn.com'
})

if (finds.length === 0) {
t.fail('add space-separated domain failed')
}
})
})
})

0 comments on commit c09bb3b

Please sign in to comment.