Skip to content

Commit

Permalink
fixed problem parsing when link node is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
harlanji committed Aug 27, 2010
1 parent b5037fa commit a608f23
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/main/javascript/activitystreams.js
Expand Up @@ -36,7 +36,7 @@ Returns:
$activity.parse = function(entryNode) {
var activity;

$(entryNode).xmlns( $activity.NS, function() {
jQuery(entryNode).xmlns( $activity.NS, function() {

activity = {
'id' : this.find("atom|id").text(),
Expand Down Expand Up @@ -124,7 +124,7 @@ $activity.object = {
*/
'parse' : function(entryNode) {
var obj;
$(entryNode).xmlns( $activity.NS, function() {
jQuery(entryNode).xmlns( $activity.NS, function() {
obj = {
'id': this.find("id").text(),
'published': this.find("atom|published").text(),
Expand Down Expand Up @@ -165,8 +165,8 @@ $activity.object = {
},

'parseFn' : function(objectNode, obj) {
obj.status = $(objectNode).find("atom|content").text();
obj.contentType = $(objectNode).find("atom|content").attr("type") || "text/plain";
obj.status = jQuery(objectNode).find("atom|content").text();
obj.contentType = jQuery(objectNode).find("atom|content").attr("type") || "text/plain";
}
};

Expand All @@ -192,9 +192,14 @@ $activity.object = {
},

'parseFn' : function(objectNode, obj) {
var linkNode = $(objectNode).find("xhtml|link");
obj.rel = linkNode.attr("rel") || "alternate";
obj.photo = linkNode.attr("href");
var linkNode = jQuery(objectNode).find("xhtml|link");
if( linkNode.length ) {
obj.rel = linkNode.attr("rel") || "alternate";
obj.photo = linkNode.attr("href");
} else {
obj.rel = "alternate";
obj.photo = "";
}
}
};

Expand Down
12 changes: 12 additions & 0 deletions src/test/javascript/ObjectTests.js
Expand Up @@ -67,4 +67,16 @@ jQuery(document).ready(function() {
equals( obj.published, "2003-12-13T18:30:02Z" );
});

test("Photo: Parse - All fields missing (no errors)", function() {

var photoNode = toDom('<object xmlns="http://activitystrea.ms/spec/1.0/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xhtml="http://www.w3.org/1999/xhtml"><object-type xmlns="http://activitystrea.ms/spec/1.0/">http://onesocialweb.org/spec/1.0/object/photo</object-type></object>');

var obj = $activity.object.parse( photoNode );

equals( obj.objectType, "http://onesocialweb.org/spec/1.0/object/photo" );
equals( obj.photo, "" );
equals( obj.rel, "alternate" );
equals( obj.published, "" );
});

});

0 comments on commit a608f23

Please sign in to comment.