diff --git a/package.json b/package.json index 04c3d0d..cafd0af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jam-my-stack", - "version": "1.0.12", + "version": "1.0.13", "repository": { "url": "https://github.com/wgroeneveld/jam-my-stack", "type": "git" diff --git a/src/mastodon/feed-parser.js b/src/mastodon/feed-parser.js index 21aaa9a..8e7264b 100644 --- a/src/mastodon/feed-parser.js +++ b/src/mastodon/feed-parser.js @@ -35,6 +35,8 @@ function convertAtomItemToMd(item, notesdir) { writeFileSync(`${path}/${item.hash}.md`, mddata, 'utf-8') } +const escQuotes = str => str.replace(/\"/g, "\\\"") + function trimIfNeeded(title, count, prefix) { if(title.length > count) { return prefix + title.substring(0, count) + "..." @@ -77,6 +79,7 @@ async function parseMastoFeed(options) { const day = date.format("DD") // format: const context = item['thr:in-reply-to'] ? item['thr:in-reply-to']['@_ref'] : "" + const title = escQuotes(ent.decode(ent.decode(item.title))) const media = item.link?.filter(l => l['@_rel'] === 'enclosure' && @@ -84,10 +87,10 @@ async function parseMastoFeed(options) { // WHY double decode? " = &#34; - first decode '&', then the other char.' return { - title: trimIfNeeded(ent.decode(ent.decode(item.title)), titleCount, titlePrefix), // summary (cut-off) of content + title: trimIfNeeded(title, titleCount, titlePrefix), // summary (cut-off) of content content: ent.decode(ent.decode(item.content['#text'])), // format: <span class="h-card.... - url: item.id, // format: https://chat.brainbaking.com/objects/0707fd54-185d-4ee7-9204-be370d57663c - context, + url: escQuotes(item.id), // format: https://chat.brainbaking.com/objects/0707fd54-185d-4ee7-9204-be370d57663c + context: escQuotes(context), id: stripBeforeLastSlash(item.id), media, hash: `${day}h${date.format("HH")}m${date.format("mm")}s${date.format("ss")}`, diff --git a/test/__mocks__/masto-feed-quote.xml b/test/__mocks__/masto-feed-quote.xml new file mode 100644 index 0000000..8bfa080 --- /dev/null +++ b/test/__mocks__/masto-feed-quote.xml @@ -0,0 +1,95 @@ + + + + https://chat.brainbaking.com/users/wouter/feed.atom + wouter's timeline + 2021-03-02T16:18:46 + https://chat.brainbaking.com/media/f39bcd85-5098-45e2-b395-e274b712d512/headshot_2020.jpg + + + + https://chat.brainbaking.com/users/wouter + http://activitystrea.ms/schema/1.0/person + https://chat.brainbaking.com/users/wouter + wouter + Wouter Groeneveld + Level 35 Brain Baker. Loving the smell of freshly baked thoughts (and bread) in the morning 🍞. Sometimes convincing others to bake their brain (and bread) too 🧠. + Level 35 Brain Baker. Loving the smell of freshly baked thoughts (and bread) in the morning 🍞. Sometimes convincing others to bake their brain (and bread) too 🧠. + wouter + + + + + + true + + + + + + + + + + + http://activitystrea.ms/schema/1.0/note + http://activitystrea.ms/schema/1.0/post + https://chat.brainbaking.com/objects/2e58289c-f5f0-415c-b2e1-62c74662aa16 + "wow this sucks" with quotes + "hi there" with quotes content + 2021-03-02T16:18:46.658056Z + 2021-03-02T16:18:46.658056Z + + tag:mastodon.social,2021-03-01:objectId=224637732:objectType=Conversation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/mastodon/feed-parser.test.js b/test/mastodon/feed-parser.test.js index 05e5059..4ac8e4c 100644 --- a/test/mastodon/feed-parser.test.js +++ b/test/mastodon/feed-parser.test.js @@ -29,6 +29,19 @@ describe("mastodon feed parser tests", () => { expect(actualMd).toMatchSnapshot() }) + test("parse prepends double quotes with backlash to escape in frontmatter", async () => { + await parseMastoFeed({ + url: "masto-feed-quote", + notesdir: dumpdir, + utcOffset: 0 + }) + + const actualMd = await fsp.readFile(`${dumpdir}/2021/03/02h16m18s46.md`) + + const md = frontMatterParser.parseSync(actualMd.toString()) + expect(md.data.title).toBe("\"wow this sucks\" with quotes") + }) + test("parse trims title according to config and adds three dots", async () => { await parseMastoFeed({ url: "masto-feed-sample",