Added Name.indexOfFileName().
diff --git a/js/Name.js b/js/Name.js
index a89ea21..1f1f843 100644
--- a/js/Name.js
+++ b/js/Name.js
@@ -177,6 +177,27 @@
return result;
}
+/*
+ * The "file name" in a name is the last component that isn't blank and doesn't start with one of the
+ * special marker octets (for version, etc.). Return the index in this.components of
+ * the file name, or -1 if not found.
+ */
+Name.prototype.indexOfFileName = function() {
+ for (var i = this.components.length - 1; i >= 0; --i) {
+ var component = this.components[i];
+ if (component.length <= 0)
+ continue;
+
+ if (component[0] == 0 || component[0] == 0xC0 || component[0] == 0xC1 ||
+ (component[0] >= 0xF5 && component[0] <= 0xFF))
+ continue;
+
+ return i;
+ }
+
+ return -1;
+}
+
/**
* Return component as an escaped string according to "CCNx URI Scheme".
* We can't use encodeURIComponent because that doesn't encode all the characters we want to.
diff --git a/js/ccnxProtocol/components/ccnxProtocolService.js b/js/ccnxProtocol/components/ccnxProtocolService.js
index 5308fdd..c57d94a 100644
--- a/js/ccnxProtocol/components/ccnxProtocolService.js
+++ b/js/ccnxProtocol/components/ccnxProtocolService.js
@@ -211,22 +211,13 @@
* for a recognized file name extension, and return an object with properties contentType and charset.
*/
function getNameContentTypeAndCharset(name) {
- var filename = "";
- for (var i = name.components.length - 1; i >= 0; --i) {
- var component = name.components[i];
- if (component.length <= 0)
- continue;
-
- // Skip special components which just may have ".gif", etc.
- if (component[0] == 0 || component[0] == 0xC0 || component[0] == 0xC1 ||
- (component[0] >= 0xF5 && component[0] <= 0xFF))
- continue;
-
- filename = DataUtils.toString(component).toLowerCase();
- break;
- }
+ var iFileName = name.indexOfFileName();
+ if (iFileName < 0)
+ // Get the default mime type.
+ return MimeTypes.getContentTypeAndCharset("");
- return MimeTypes.getContentTypeAndCharset(filename);
+ return MimeTypes.getContentTypeAndCharset
+ (DataUtils.toString(name.components[iFileName]).toLowerCase());
}
/*