Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

validate regtype strings

  • Loading branch information...
commit e6143c15400eb636ccbbd8096f7691b50be1b16a 1 parent db21ebe
@agnat authored
View
19 lib/regtype.js
@@ -1,11 +1,30 @@
+function checkLengthAndCharset(str) {
+ if (str.length > 14) {
+ throw new Error('type ' + str + ' has more than 14 characters');
+ }
+ var re = new RegExp('[^-a-zA-Z0-9]');
+ if (str.match(re)) {
+ throw new Error('type ' + str + ' may only consist of alphanumeric characters and hyphens');
+ }
+}
+
function RegType(types, transportProtocol) {
var self = this;
if (! (types instanceof Array)) {
types = [types];
}
types = types.slice();
+ if (types.length < 1) {
+ throw new Error('no service name given');
+ }
self.serviceType = types.shift();
+
+ checkLengthAndCharset(self.serviceType);
+
self.subtypes = types;
+
+ self.subtypes.forEach(function(t) { checkLengthAndCharset(t); });
+
self.transportProtocol = transportProtocol || 'tcp';
}
View
4 lib/resolver.js
@@ -20,7 +20,7 @@ function Resolver(name, regtype, domain, options, callback) {
context = options.context || null;
self.callback = callback
- self.withAddress = options.withAddress || true;
+ self.resolveAddress = options.resolveAddress || true;
capi.dnsServiceResolve(self.serviceRef, flags, ifaceIdx, name, regtype,
domain, self._onResolve, context);
@@ -42,7 +42,7 @@ Resolver.prototype._onResolve = function(sdRef, flags, interfaceIndex,
if (txtRecord) info.txtRecord = txtRecord;
if (context) info.context = context;
- if (self.withAddress) {
+ if (self.resolveAddress) {
var addressInfoGetter = new MDNSService();
var addresses = [];
capi.dnsServiceGetAddrInfo(addressInfoGetter.serviceRef, 0, 0, 0, hosttarget,
View
12 tests/oo_layer/test-0010-Advertisement
@@ -6,25 +6,25 @@ var mdns = require('../../lib/mdns'),
var t = 500; // ms
-var ad1 = mdns.createAdvertisement('node-mdns-test1', 4321);
+var ad1 = mdns.createAdvertisement('mdns-test1', 4321);
ad1.start();
setTimeout(function() { ad1.stop() }, t);
-var ad2 = mdns.createAdvertisement('node-mdns-test2', 4322, {});
+var ad2 = mdns.createAdvertisement('mdns-test2', 4322, {});
ad2.start();
setTimeout(function() { ad2.stop() }, t);
-var ad3 = mdns.createAdvertisement('node-mdns-test3', 4323, function(error, info, flags) {
+var ad3 = mdns.createAdvertisement('mdns-test3', 4323, function(error, info, flags) {
if (error) assert.fail(error);
var ad = this;
- setTimeout(function(){ ad.stop(); }, t);
+ setTimeout(function(){ ad.stop() }, t);
});
ad3.start();
-var ad4 = mdns.createAdvertisement('node-mdns-test4', 4324, {}, function(error, info, flags) {
+var ad4 = mdns.createAdvertisement('mdns-test4', 4324, {}, function(error, info, flags) {
if (error) assert.fail(error);
var ad = this;
- setTimeout(function(){ ad.stop(); }, t);
+ setTimeout(function(){ ad.stop() }, t);
});
ad4.start();
View
2  tests/oo_layer/test-0020-Browser
@@ -54,7 +54,7 @@ browser.on('serviceUp', function(info, flags) {
assert.ok(info.addresses instanceof Array);
assert.ok(info.addresses.length > 0);
- //sys.puts(sys.inspect(info));
+ sys.puts(sys.inspect(info));
upCount += 1;
stopBrowserIfDone();
View
5 tests/oo_layer/test-0040-RegType
@@ -10,5 +10,10 @@ assert.strictEqual( mdns.tcp('http', 'blogapi').toString(), '_http._tcp,_blogapi
assert.strictEqual( mdns.tcp('http', 'blogapi', 'newblogapi').toString(),
'_http._tcp,_blogapi,_newblogapi');
+assert.throws(function() { mdns.tcp('abcdefghijklmnopq') });
+assert.throws(function() { mdns.tcp('abc%') });
+assert.throws(function() { mdns.tcp('abc', 'abcdefghijklmnopq') });
+assert.throws(function() { mdns.tcp('abc', '%$@') });
+assert.throws(function() { mdns.tcp('abc', 'def', '_narf') });
// vim: filetype=javascript:
Please sign in to comment.
Something went wrong with that request. Please try again.