Addresses #821, Validate URL in linkFromURL() before calling doHead()

Not fixing this in the attachments layer -- even if I corrected URLs in the attachments layer, the translation layer would still revert them to the original. Instead, importFromURL() and linkFromURL() will now just throw an explicit error if passed an invalid URL.
This commit is contained in:
Dan Stillman 2007-12-17 21:53:26 +00:00
parent 33a9af4e1b
commit 572f31a5bd

View File

@ -174,6 +174,13 @@ Zotero.Attachments = new function(){
function importFromURL(url, sourceItemID, forceTitle, forceFileBaseName, parentCollectionIDs){
Zotero.debug('Importing attachment from URL');
// Throw error on invalid URLs
urlRe = /^https?:\/\/[^\s]*$/;
var matches = urlRe.exec(url);
if (!matches) {
throw ("Invalid URL '" + url + "' in Zotero.Attachments.importFromURL()");
}
Zotero.Utilities.HTTP.doHead(url, function(obj){
var mimeType = obj.channel.contentType;
@ -343,6 +350,13 @@ Zotero.Attachments = new function(){
function linkFromURL(url, sourceItemID, mimeType, title){
Zotero.debug('Linking attachment from URL');
// Throw error on invalid URLs
urlRe = /^https?:\/\/[^\s]*$/;
var matches = urlRe.exec(url);
if (!matches) {
throw ("Invalid URL '" + url + "' in Zotero.Attachments.linkFromURL()");
}
// If no title provided, figure it out from the URL
if (!title){
title = url.substring(url.lastIndexOf('/')+1);