TiddlyWiki.org

Ticket #635 (closed defect: fixed)

Opened 3 months ago

Last modified 3 months ago

importing under Windows Vista

Reported by: FND Assigned to: JeremyRuston
Priority: critical Milestone: 2.5
Component: core Version:
Severity: high Keywords:
Cc:

Description

As reported here, importing from a local file does not work under Windows Vista.

When browsing for a local file, the txtPath field is incorrectly populated (e.g. file://C:\foo\bar.html).

Change History

17/05/08 03:56:32 changed by EricShulman

The problem occurs here:

config.macros.importTiddlers.onBrowseChange = function(e)
{
	var wizard = new Wizard(this);
	var fileInput = wizard.getElement("txtPath");
	fileInput.value = "file://" + this.value;
	var serverType = wizard.getElement("selTypes");
	serverType.value = "file";
	return false;
};

the fix is to use three backslashes instead of two:

	fileInput.value = "file:///" + this.value;

(follow-up: ↓ 3 ) 17/05/08 16:00:02 changed by EricShulman

Note: in addition to simply pre-pending "file:///", the following code also resolves *relative* path/file references, allowing the user to simply enter (or paste) the name of a file located in same directory as the current document:

config.macros.importTiddlers.onBrowseChange = function(e)
{
	...
	fileInput.value = config.macros.importTiddlers.getURLFromLocalPath (this.value);
	...
};
// fixup local path/file to form absolute URL reference
config.macros.importTiddlers.getURLFromLocalPath = function(v)
{
	if (!v||!v.length) return v;
	v=v.replace(/\\/g,"/"); // use "/" for cross-platform consistency
	var t=v.split(":"); p=t[1]||t[0]; // remove drive letter (if any)
	if (t[1] && (t[0]=="http"||t[0]=="https"||t[0]=="file")) return v; // input is already a URL
	if (p.substr(0,1)=="/")	return "file:///"+v; // path is absolute, just append "file:///"
	// path is relative, add current document path
	var c=document.location.href.replace(/\\/g,"/");
	var pos=c.lastIndexOf("/"); if (pos!=-1) c=c.substr(0,pos); // remove filename
	return c+"/"+p;
}

(in reply to: ↑ 2 ) 17/05/08 18:57:00 changed by EricShulman

code from above, revised for more robust handling when importing from online documents:

config.macros.importTiddlers.getURLFromLocalPath = function(v)
{
	if (!v||!v.length) return v;
	v=v.replace(/\\/g,"/"); // use "/" for cross-platform consistency
	var t=v.split(":"); p=t[1]||t[0]; // remove drive letter (if any)
	if (t[1] && (t[0]=="http"||t[0]=="https"||t[0]=="file")) { // input is already a URL
		var u=v;
	} else if (p.substr(0,1)=="/") { // path is absolute, add protocol+domain
		var u=document.location.protocol+"//"+document.location.hostname+v;
	} else { // path is relative, add current document protocol+domain+path
		var c=document.location.href.replace(/\\/g,"/");
		var pos=c.lastIndexOf("/"); if (pos!=-1) c=c.substr(0,pos); // remove filename
		var u=c+"/"+p;
	}
	return u;
}}}}

20/05/08 17:15:22 changed by MartinBudden

First part (file:///) Fixed in changeset:5079

21/05/08 15:28:40 changed by MartinBudden

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in changeset:5116