Skip to content

Commit

Permalink
allow data protocol in images
Browse files Browse the repository at this point in the history
closes #721
  • Loading branch information
jhchen committed Jun 3, 2016
1 parent 3525e2d commit 74fc8bb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions formats/image.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Embed from '../blots/embed';
import Link from '../formats/link';
import Link, { sanitize } from '../formats/link';


class Image extends Embed {
Expand All @@ -16,7 +16,7 @@ class Image extends Embed {
}

static sanitize(url) {
return Link.sanitize(url);
return sanitize(url, ['http', 'https', 'data']) ? url : '//:0';
}

static value(domNode) {
Expand Down
19 changes: 10 additions & 9 deletions formats/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ class Link extends Inline {
}

static sanitize(url) {
let anchor = document.createElement('a');
anchor.href = url;
let protocol = anchor.href.slice(0, anchor.href.indexOf(':'));
if (['http', 'https', 'mailto'].indexOf(protocol) > -1) {
return url;
} else {
return this.SANITIZED_URL;
}
return sanitize(url, ['http', 'https', 'mailto']) ? url : this.SANITIZED_URL;
}

format(name, value) {
Expand All @@ -36,4 +29,12 @@ Link.tagName = 'A';
Link.SANITIZED_URL = 'about:blank';


export default Link;
function sanitize(url, protocols) {
let anchor = document.createElement('a');
anchor.href = url;
let protocol = anchor.href.slice(0, anchor.href.indexOf(':'));
return protocols.indexOf(protocol) > -1;
}


export { Link as default, sanitize };

0 comments on commit 74fc8bb

Please sign in to comment.