-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trim string before parsing IP address (#269)
Remove leading and training spaces, also adds tests.
- Loading branch information
1 parent
d6b7f69
commit 9924afa
Showing
3 changed files
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* eslint max-nested-callbacks: ["error", 8] */ | ||
/* eslint-env mocha */ | ||
import { expect } from 'aegir/chai' | ||
import { toBytes, toString } from '../src/ip.js' | ||
|
||
describe('ip', () => { | ||
describe('toBytes', () => { | ||
it('should handle extra characters', () => { | ||
const address = '127.0.0.1 ' | ||
const bytes = toBytes(address) | ||
|
||
expect(toString(bytes)).to.equal(address.trim()) | ||
}) | ||
|
||
it('should turn loopback into bytes', () => { | ||
const address = '127.0.0.1' | ||
const bytes = toBytes(address) | ||
|
||
expect(toString(bytes)).to.equal(address) | ||
}) | ||
|
||
it('should turn private address into bytes', () => { | ||
const address = '192.168.1.1' | ||
const bytes = toBytes(address) | ||
|
||
expect(toString(bytes)).to.equal(address) | ||
}) | ||
}) | ||
}) |