Skip to content

Commit

Permalink
fix: XML escape package description (#3)
Browse files Browse the repository at this point in the history
Packages with characters not legal in XML (for example &) in package description are rejected by Cholatey client, with malformed XML message. This pull request fixes that.
  • Loading branch information
joeyparrish committed Oct 4, 2023
2 parents f3c78d0 + e17e3e4 commit 71068d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chocolatey-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const AdmZip = require('adm-zip');
const express = require('express');
const fs = require('fs/promises');
const xmldoc = require('xmldoc');
const xmlescape = require('xml-escape');

const CONTENT_TYPE = 'Content-Type';
const ATOM_MIME_TYPE = 'application/atom+xml; charset=utf-8';
Expand Down Expand Up @@ -174,7 +175,7 @@ async function configureRoutes(app, prefix, packageMetadataList) {

function formatPackages(matchedPackages, req) {
const entries = matchedPackages.map((entry) => {
return entryTemplate.replace(/{(.*)}/g, (match, key) => entry[key] || '');
return entryTemplate.replace(/{(.*)}/g, (match, key) => xmlescape(entry[key]) || '');
});

const url_root = req.protocol + '://' + req.get('host');
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"adm-zip": "^0.5.9",
"express": "^4.18.2",
"xml-escape": "^1.1.0",
"xmldoc": "^1.2.0"
},
"engines": {
Expand Down

0 comments on commit 71068d4

Please sign in to comment.