diff --git a/js/lib/mediawiki.WikitextSerializer.js b/js/lib/mediawiki.WikitextSerializer.js
index <HASH>..<HASH> 100644
--- a/js/lib/mediawiki.WikitextSerializer.js
+++ b/js/lib/mediawiki.WikitextSerializer.js
@@ -1480,6 +1480,14 @@ WSP._serializeToken = function ( state, token ) {
 
 	if (! dropContent || ! state.dropContent ) {
 		var newTrailingNLCount = 0;
+
+		// FIXME: figure out where the non-string res comes from
+		if (res !== '' && res.constructor !== String) {
+			console.err("res was not a string!");
+			console.trace();
+			res = '';
+		}
+
 		if (res !== '') {
 			// Strip leading or trailing newlines from the returned string
 			var match = res.match( /^((?:\r?\n)*)((?:.*?|[\r\n]+[^\r\n])*?)((?:\r?\n)*)$/ ),
Work around a serializer crash exposed by rt tests

Change-Id: I<I>e5cd3d<I>cb<I>c6a4c<I>b<I>