Fix message parser

This commit is contained in:
Mattias Erming 2014-10-12 00:57:34 +02:00
parent aa02b0eaa7
commit 5b1820ca2e
3 changed files with 65 additions and 64 deletions

22
client/js/libs.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -35,12 +35,16 @@ function escape(text) {
} }
function uri(text) { function uri(text) {
return URI.withinString(text, function(url) { return URI.withinString(text, function(url, start, end, source) {
if (url.indexOf("javascript:") !== 0) { if (url.indexOf("javascript:") === 0) {
return "<a href='" + url.replace(/^www/, "//www") + "' target='_blank'>" + url + "</a>";
} else {
return url; return url;
} }
var split = url.split("<");
url = "<a href='" + split[0].replace(/^www/, "//www") + "' target='_blank'>" + split[0] + "</a>";
if (split[1]) {
url += "<" + split[1];
}
return url;
}); });
} }

View File

@ -1,7 +1,7 @@
/*! /*!
* URI.js - Mutating URLs * URI.js - Mutating URLs
* *
* Version: 1.13.2 * Version: 1.14.1
* *
* Author: Rodney Rehm * Author: Rodney Rehm
* Web: http://medialize.github.io/URI.js/ * Web: http://medialize.github.io/URI.js/
@ -57,7 +57,7 @@
return this; return this;
} }
URI.version = '1.13.2'; URI.version = '1.14.1';
var p = URI.prototype; var p = URI.prototype;
var hasOwn = Object.prototype.hasOwnProperty; var hasOwn = Object.prototype.hasOwnProperty;
@ -225,7 +225,9 @@
'embed': 'src', 'embed': 'src',
'source': 'src', 'source': 'src',
'track': 'src', 'track': 'src',
'input': 'src' // but only if type="image" 'input': 'src', // but only if type="image"
'audio': 'src',
'video': 'src'
}; };
URI.getDomAttribute = function(node) { URI.getDomAttribute = function(node) {
if (!node || !node.nodeName) { if (!node || !node.nodeName) {
@ -365,9 +367,17 @@
var _part; var _part;
var generateAccessor = function(_group, _part) { var generateAccessor = function(_group, _part) {
return function(string) { return function(string) {
try {
return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function(c) { return URI[_part](string + '').replace(URI.characters[_group][_part].expression, function(c) {
return URI.characters[_group][_part].map[c]; return URI.characters[_group][_part].map[c];
}); });
} catch (e) {
// we're not going to mess with weird encodings,
// give up and return the undecoded original string
// see https://github.com/medialize/URI.js/issues/87
// see https://github.com/medialize/URI.js/issues/92
return string;
}
}; };
}; };
@ -414,9 +424,6 @@
if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) { if (parts.protocol && !parts.protocol.match(URI.protocol_expression)) {
// : may be within the path // : may be within the path
parts.protocol = undefined; parts.protocol = undefined;
} else if (parts.protocol === 'file') {
// the file scheme: does not contain an authority
string = string.substring(pos + 3);
} else if (string.substring(pos + 1, pos + 3) === '//') { } else if (string.substring(pos + 1, pos + 3) === '//') {
string = string.substring(pos + 3); string = string.substring(pos + 3);
@ -480,11 +487,7 @@
URI.parseUserinfo = function(string, parts) { URI.parseUserinfo = function(string, parts) {
// extract username:password // extract username:password
var firstSlash = string.indexOf('/'); var firstSlash = string.indexOf('/');
/*jshint laxbreak: true */ var pos = string.lastIndexOf('@', firstSlash > -1 ? firstSlash : string.length - 1);
var pos = firstSlash > -1
? string.lastIndexOf('@', firstSlash)
: string.indexOf('@');
/*jshint laxbreak: false */
var t; var t;
// authority@ must come before /path // authority@ must come before /path
@ -524,7 +527,7 @@
// no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters // no "=" is null according to http://dvcs.w3.org/hg/url/raw-file/tip/Overview.html#collect-url-parameters
value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null; value = v.length ? URI.decodeQuery(v.join('='), escapeQuerySpace) : null;
if (items[name]) { if (hasOwn.call(items, name)) {
if (typeof items[name] === 'string') { if (typeof items[name] === 'string') {
items[name] = [items[name]]; items[name] = [items[name]];
} }
@ -657,7 +660,7 @@
value = [value]; value = [value];
} }
data[name] = data[name].concat(value); data[name] = (data[name] || []).concat(value);
} else { } else {
throw new TypeError('URI.addQuery() accepts an object, string as the name parameter'); throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
} }
@ -882,9 +885,8 @@
return this.build(false)._string; return this.build(false)._string;
}; };
// generate simple accessors
_parts = {protocol: 'protocol', username: 'username', password: 'password', hostname: 'hostname', port: 'port'}; function generateSimpleAccessor(_part){
generateAccessor = function(_part){
return function(v, build) { return function(v, build) {
if (v === undefined) { if (v === undefined) {
return this._parts[_part] || ''; return this._parts[_part] || '';
@ -894,15 +896,9 @@
return this; return this;
} }
}; };
};
for (_part in _parts) {
p[_part] = generateAccessor(_parts[_part]);
} }
// generate accessors with optionally prefixed input function generatePrefixAccessor(_part, _key){
_parts = {query: '?', fragment: '#'};
generateAccessor = function(_part, _key){
return function(v, build) { return function(v, build) {
if (v === undefined) { if (v === undefined) {
return this._parts[_part] || ''; return this._parts[_part] || '';
@ -919,24 +915,24 @@
return this; return this;
} }
}; };
};
for (_part in _parts) {
p[_part] = generateAccessor(_part, _parts[_part]);
} }
// generate accessors with prefixed output p.protocol = generateSimpleAccessor('protocol');
_parts = {search: ['?', 'query'], hash: ['#', 'fragment']}; p.username = generateSimpleAccessor('username');
generateAccessor = function(_part, _key){ p.password = generateSimpleAccessor('password');
return function(v, build) { p.hostname = generateSimpleAccessor('hostname');
var t = this[_part](v, build); p.port = generateSimpleAccessor('port');
return typeof t === 'string' && t.length ? (_key + t) : t; p.query = generatePrefixAccessor('query', '?');
}; p.fragment = generatePrefixAccessor('fragment', '#');
};
for (_part in _parts) { p.search = function(v, build) {
p[_part] = generateAccessor(_parts[_part][1], _parts[_part][0]); var t = this.query(v, build);
} return typeof t === 'string' && t.length ? ('?' + t) : t;
};
p.hash = function(v, build) {
var t = this.fragment(v, build);
return typeof t === 'string' && t.length ? ('#' + t) : t;
};
p.pathname = function(v, build) { p.pathname = function(v, build) {
if (v === undefined || v === true) { if (v === undefined || v === true) {
@ -978,8 +974,8 @@
href = href.toString(); href = href.toString();
} }
if (typeof href === 'string') { if (typeof href === 'string' || href instanceof String) {
this._parts = URI.parse(href, this._parts); this._parts = URI.parse(String(href), this._parts);
} else if (_URI || _object) { } else if (_URI || _object) {
var src = _URI ? href._parts : href; var src = _URI ? href._parts : href;
for (key in src) { for (key in src) {
@ -1485,7 +1481,7 @@
segments.push(v[i]); segments.push(v[i]);
} }
} else if (v || (typeof v === 'string')) { } else if (v || typeof v === 'string') {
if (segments[segments.length -1] === '') { if (segments[segments.length -1] === '') {
// empty trailing elements have to be overwritten // empty trailing elements have to be overwritten
// to prevent results such as /foo//bar // to prevent results such as /foo//bar
@ -1495,7 +1491,7 @@
} }
} }
} else { } else {
if (v || (typeof v === 'string' && v.length)) { if (v) {
segments[segment] = v; segments[segment] = v;
} else { } else {
segments.splice(segment, 1); segments.splice(segment, 1);
@ -1531,7 +1527,7 @@
} }
if (!isArray(v)) { if (!isArray(v)) {
v = typeof v === 'string' ? URI.encode(v) : v; v = (typeof v === 'string' || v instanceof String) ? URI.encode(v) : v;
} else { } else {
for (i = 0, l = v.length; i < l; i++) { for (i = 0, l = v.length; i < l; i++) {
v[i] = URI.decode(v[i]); v[i] = URI.decode(v[i]);
@ -1563,14 +1559,14 @@
p.setQuery = function(name, value, build) { p.setQuery = function(name, value, build) {
var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace); var data = URI.parseQuery(this._parts.query, this._parts.escapeQuerySpace);
if (typeof name === 'object') { if (typeof name === 'string' || name instanceof String) {
data[name] = value !== undefined ? value : null;
} else if (typeof name === 'object') {
for (var key in name) { for (var key in name) {
if (hasOwn.call(name, key)) { if (hasOwn.call(name, key)) {
data[key] = name[key]; data[key] = name[key];
} }
} }
} else if (typeof name === 'string') {
data[name] = value !== undefined ? value : null;
} else { } else {
throw new TypeError('URI.addQuery() accepts an object, string as the name parameter'); throw new TypeError('URI.addQuery() accepts an object, string as the name parameter');
} }
@ -2004,3 +2000,4 @@
return URI; return URI;
})); }));