Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mehdown

Package Overview
Dependencies
Maintainers
1
Versions
134
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mehdown - npm Package Compare versions

Comparing version 1.11.1 to 1.11.2

40

lib/index.js

@@ -43,4 +43,4 @@ var Mehdown;

text = text.replace(Mehdown.urlRegExp, function() {
var domain = arguments[1];
var href = (domain.indexOf('http') < 0) ? 'http://' + domain : domain;
var url = arguments[1];
var href = (url.indexOf('http') < 0) ? 'http://' + url : url;
var preceding = text.substring(0, arguments[2]);

@@ -50,5 +50,5 @@ var insideTagAttrRegex = /<(?!\/)[^>]+(?!>)$/g;

// use the correct protocol if domain is baseUrl domain
if (href !== Mehdown.baseUrl && href.split('/')[2] === Mehdown.baseUrl.split('/')[2]) {
href = Mehdown.baseUrl.split('://')[0] + '://' + domain;
// use the correct protocol if href contains baseUrl domain
if (href.split('/')[2] === Mehdown.baseUrl.split('/')[2] && href.split(':')[0] !== Mehdown.baseUrl.split(':')[0]) {
href = Mehdown.baseUrl.split('://')[0] + '://' + href.replace(/^https?:\/\//, '');
}

@@ -58,22 +58,34 @@

if (preceding.match(insideTagAttrRegex) || preceding.match(insideAnchorTagRegex)) {
return domain;
return url;
}
// don't use http protocol on email adresses
if (domain.indexOf('@') >= 0) {
var parts = domain.split('@');
if (parts[1].match(Mehdown.urlRegExp)) {
href = 'mailto:' + domain;
if (url.indexOf('@') >= 0 && !url.split('@')[0].match(Mehdown.urlRegExp)) {
if (url.split('@')[1].match(Mehdown.urlRegExp)) {
href = 'mailto:' + url;
} else {
// this is a wierd something@something-no-tld that the regex thinks is a url, abort
return domain;
// this is a weird something@something-no-tld that the regex thinks is a url, abort
return url;
}
}
return '<a href="' + href + '">' + domain + '</a>';
return '<a href="' + href + '">' + url + '</a>';
});
// Usernames
text = text.replace(Mehdown.usernameRegExp, '$1' + Mehdown.username('$2'));
text = text.replace(Mehdown.usernameRegExp, function() {
var precedingNonWord = arguments[1];
var username = arguments[2];
var preceding = text.substring(0, arguments[3]);
var insideTagAttrRegex = /<(?!\/)[^>]+(?!>)$/g;
var insideAnchorTagRegex = /<a[^>]*>.+(?!<\/a>)$/g;
// inside tag attr or anchor tag, abort
if (preceding.match(insideTagAttrRegex) || preceding.match(insideAnchorTagRegex)) {
return precedingNonWord + '@' + username;
}
return precedingNonWord + Mehdown.username(username);
});
// Imgur GIFV: http://imgur.com/blog/2014/10/09/introducing-gifv/

@@ -80,0 +92,0 @@ text = text.replace(/<a href="https?:\/\/(?:i\.)?(?:imgur\.com\/)(\w+)\.gifv">https?:\/\/(?:i\.)?(?:imgur\.com\/)(\w+)\.gifv<\/a>/gi, Mehdown.imgurGifv('$1'));

@@ -13,3 +13,3 @@ {

},
"version": "1.11.1"
"version": "1.11.2"
}

@@ -184,2 +184,22 @@ var assert = require('assert');

});
it('mediocre.com/@username', function() {
var text = mehdown.parse('mediocre.com/@username');
assert.equal(text, '<a href="https://mediocre.com/@username">mediocre.com/@username</a>');
});
it('http://mediocre.com/@username', function() {
var text = mehdown.parse('http://mediocre.com/@username');
assert.equal(text, '<a href="https://mediocre.com/@username">http://mediocre.com/@username</a>');
});
it('https://mediocre.com/@username', function() {
var text = mehdown.parse('https://mediocre.com/@username');
assert.equal(text, '<a href="https://mediocre.com/@username">https://mediocre.com/@username</a>');
});
it('<a href="https://mediocre.com/@username">@username</a>', function() {
var text = mehdown.parse('<a href="https://mediocre.com/@username">@username</a>');
assert.equal(text, '<a href="https://mediocre.com/@username">@username</a>');
});
});

@@ -186,0 +206,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc