Skip to content
Permalink
Browse files

Exposes encodeXML lambda

  • Loading branch information...
davidmerfield committed Aug 30, 2019
1 parent 5a71447 commit 09c01c062f691c79cb7b019ced66e0d15558a0d3
Showing with 11 additions and 28 deletions.
  1. +10 −28 app/blog/render/retrieve/encodeXML.js
  2. +1 −0 app/blog/render/retrieve/index.js
@@ -1,47 +1,29 @@
/*
This function accepts some HTML makes it suitable for
inclusion in a CDATA-fenced description tag for an RSS
feed item. It resolves relative URLs to make the result
more portable. It should help produce valid feeds.
*/
// This function accepts some HTML makes it suitable for
// inclusion in a CDATA-fenced description tag for an RSS
// feed item. It resolves relative URLs to make the result
// more portable. It should help produce valid feeds.

var absoluteURLs = require('./absoluteURLs').absoluteURLs;

// Removes everything forbidden by XML 1.0 specifications,
// plus the unicode replacement character U+FFFD
function removeXMLInvalidChars(string) {
// remove everything forbidden by XML 1.0 specifications, plus the unicode replacement character U+FFFD
var regex = /((?:[\0-\x08\x0B\f\x0E-\x1F\uFFFD\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]))/g;

string = string.replace(regex, "");

// removes everything not suggested by XML 1.0 specifications
// regex = new RegExp(
// "([\\x7F-\\x84]|[\\x86-\\x9F]|[\\uFDD0-\\uFDEF]|(?:\\uD83F[\\uDFFE\\uDFFF])|(?:\\uD87F[\\uDF" +
// "FE\\uDFFF])|(?:\\uD8BF[\\uDFFE\\uDFFF])|(?:\\uD8FF[\\uDFFE\\uDFFF])|(?:\\uD93F[\\uDFFE\\uD" +
// "FFF])|(?:\\uD97F[\\uDFFE\\uDFFF])|(?:\\uD9BF[\\uDFFE\\uDFFF])|(?:\\uD9FF[\\uDFFE\\uDFFF])" +
// "|(?:\\uDA3F[\\uDFFE\\uDFFF])|(?:\\uDA7F[\\uDFFE\\uDFFF])|(?:\\uDABF[\\uDFFE\\uDFFF])|(?:\\" +
// "uDAFF[\\uDFFE\\uDFFF])|(?:\\uDB3F[\\uDFFE\\uDFFF])|(?:\\uDB7F[\\uDFFE\\uDFFF])|(?:\\uDBBF" +
// "[\\uDFFE\\uDFFF])|(?:\\uDBFF[\\uDFFE\\uDFFF])(?:[\\0-\\t\\x0B\\f\\x0E-\\u2027\\u202A-\\uD7FF\\" +
// "uE000-\\uFFFF]|[\\uD800-\\uDBFF][\\uDC00-\\uDFFF]|[\\uD800-\\uDBFF](?![\\uDC00-\\uDFFF])|" +
// "(?:[^\\uD800-\\uDBFF]|^)[\\uDC00-\\uDFFF]))",
// "g"
// );
// string = string.replace(regex, "");

return string;
return string.replace(regex, "");
}

module.exports = function (req, callback) {
return callback(null, function() {
return function(text, render) {
var xml;

text = render(text);

try {
xml = absoluteURLs(req.protocol + "://" + req.get("host"), text);
xml = removeXMLInvalidChars(text);
xml = removeXMLInvalidChars(xml);
} catch (e) {
console.log(e);
// do nothing if we can't
}

@@ -17,6 +17,7 @@ var dictionary = {
css_url: require("./css_url"),
encodeJSON: require("./encodeJSON"),
encodeURIComponent: require("./encodeURIComponent"),
encodeXML: require("./encodeXML"),
feed_url: require("./feed_url"),
isActive: require("./isActive"),
latestEntry: require("./latestEntry"),

0 comments on commit 09c01c0

Please sign in to comment.
You can’t perform that action at this time.