commit 5c430954f2961e2b3ae58693ab2aa5b7c6b71e61
parent 0a0b809d5565fa07133413198448202b20569a00
Author: Jared Tobin <jared@jtobin.io>
Date: Sat, 1 Dec 2018 03:37:05 +1300
Short circuit on isValidPat when no tilde.
Ensures that we get a sane 'false' answer for empty strings.
Diffstat:
4 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
@@ -1,5 +1,9 @@
# Changelog
+- 3.1.1 (2018-12-01)
+ * Short-circuit on isValidPatp and isValidPatq when there is no leading
+ tilde.
+
- 3.1.0 (2018-11-16)
* Exports 'isValidPatp' and 'isValidPatq' functions for checking the
validity of @p and @q strings.
diff --git a/package.json b/package.json
@@ -1,6 +1,6 @@
{
"name": "urbit-ob",
- "version": "3.1.0",
+ "version": "3.1.1",
"description": "Utilities for Hoon-style atom printing and conversion",
"main": "src/index.js",
"scripts": {
diff --git a/src/internal/co.js b/src/internal/co.js
@@ -366,15 +366,20 @@ const isValidPat = name => {
const syls = patp2syls(name)
const leadingTilde = name.slice(0, 1) === '~'
- const wrongLength = syls.length % 2 !== 0 && syls.length !== 1
- const sylsExist = lodash.reduce(syls, (acc, syl, index) =>
- acc &&
- (index % 2 !== 0 || syls.length === 1
- ? suffixes.includes(syl)
- : prefixes.includes(syl)),
- true)
-
- return leadingTilde && !wrongLength && sylsExist
+
+ if (leadingTilde === false) {
+ return false
+ } else {
+ const wrongLength = syls.length % 2 !== 0 && syls.length !== 1
+ const sylsExist = lodash.reduce(syls, (acc, syl, index) =>
+ acc &&
+ (index % 2 !== 0 || syls.length === 1
+ ? suffixes.includes(syl)
+ : prefixes.includes(syl)),
+ true)
+
+ return !wrongLength && sylsExist
+ }
}
/**
diff --git a/test/co.test.js b/test/co.test.js
@@ -209,6 +209,7 @@ describe('isValidPat{q, p}', () => {
})
it('isValidPatp returns false for invalid @p values', () => {
+ expect(isValidPatp('')).to.equal(false)
expect(isValidPatp('~hu')).to.equal(false)
expect(isValidPatp('~what')).to.equal(false)
expect(isValidPatp('sudnit-duntom')).to.equal(false)
@@ -222,6 +223,7 @@ describe('isValidPat{q, p}', () => {
})
it('isValidPatq returns false for invalid @p values', () => {
+ expect(isValidPatq('')).to.equal(false)
expect(isValidPatq('~hu')).to.equal(false)
expect(isValidPatq('~what')).to.equal(false)
expect(isValidPatq('sudnit-duntom')).to.equal(false)