Skip to content

Commit 5db3681

Browse files
author
Chris K
committed
Fixed short_url for data URIs.
1 parent d3589e6 commit 5db3681

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/scripts/uri.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var URIPrototype = function(uri_prop_name)
2222
short_distinguisher // the last part of a url that can be used to distinguish it
2323
*/
2424

25+
var DATA_URI_LENGTH_SHORT = 25;
26+
2527
[
2628
"hash",
2729
"host",
@@ -132,7 +134,12 @@ var URIPrototype = function(uri_prop_name)
132134
if (this._short_url === undefined && (this._is_parsed || this[uri_prop_name]))
133135
{
134136
if (this._is_data_uri)
135-
this._short_url = (this._protocol + this._pathname).slice(0, 20) + "…";
137+
{
138+
var short_url = this._protocol + this._pathname;
139+
this._short_url = short_url.length <= DATA_URI_LENGTH_SHORT
140+
? short_url
141+
: short_url.slice(0, DATA_URI_LENGTH_SHORT) + "…";
142+
}
136143
else
137144
this._short_url = this.filename || this.basename || this.host;
138145
}

tests/uri.qunit.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
equal(uri.abs_dir, "");
150150
equal(uri.basename, "");
151151
equal(uri.filename, "");
152-
equal(uri.short_url, "data:text/plain,a");
152+
equal(uri.short_url, "data:text/plain,a");
153153

154154
var uri = new URI("data:text/plain,abcdefghijklmnopqrstuvwxyz");
155155
equal(uri.protocol, "data:");
@@ -159,7 +159,7 @@
159159
equal(uri.abs_dir, "");
160160
equal(uri.basename, "");
161161
equal(uri.filename, "");
162-
equal(uri.short_url, "data:text/plain,abcd…");
162+
equal(uri.short_url, "data:text/plain,abcdefghi…");
163163

164164
});
165165

0 commit comments

Comments
 (0)