Strange encoding issue
-
Trying to write a nodebb plugin but I'm experiencing some strange result when trying to parse a post (0.7.0 latest).
I'm picking up the data from
data.postData.content
which contains a a-tag with url like this:But the parameter-separator & of the url turn into
&
which makes it really hard to pick up the parameter-values....nggood.com/New-Version-Upgraded-Hubsan-X4-H107-2_4G-4CH-Remote-Control-RC-Quadcopter-p-71838.html?ss=hej
&
;p=4711Are there any preprocessing going on before handing over the parse post data? It happens to all urls in the post with parameters.
(I've moved up my plugin to run first of all in the prio queue)
-
Hasn't anyone noticed this problem?
All link processing in a plugins will become much more hackey where I have to
Embed.parse = function(data, callback) { var match = /<a\s+[^>]*href="([^"]*)"[^>]*>/i.exec(data.postData.content); var url = match[1]; // <-- In this url all parameter is separated by & instead of & // Ugly fix realUrl = replace(/\&/g, '&'); // Should I change it back to & before doing callback? ..... }
Somewhere in the pipe after plugin.parse url:s get translated back by NodeBB so this isn't visible in the forum. But I want to manipulate the url parameter on-it's-way to the end-user.
-
At default priority (5) and run before markdown, you should be seeing the link before it turns into an anchor tag. Make sure your plugin is executed before markdown (though it does seem like you did that already...)
Maybe if you set priority of 4 for the
parse.post
hook, that might do it. -
Yes, that's it! Setting prio 4 gives access to the markup.
I'd also like to add a custom "card" at the bottom of the post (like in github-issue plugin). But what happens if I start inserting a html template in this phase? Guess it will mess up markup parsing in a later phase? The plugin.json looks like this:
{ "id": "nodebb-plugin-affiliate", "name": "Affiliate", "description": "Earn money on your user generated content. Converts links in posts to affiliate variants (ebay, aliexpress, amazon, banggood, ...). With an optional box showing product image, price and stock availablility.", "url": "https://github.com/henrikekblad/nodebb-plugin-affiliate", "library": "./index.js", "templates": "templates", "less": [ "less/default.less" ], "hooks": [ { "hook": "filter:parse.post", "method": "parse", "priority": 4 }, { "hook": "filter:parse.raw", "method": "parse", "priority": 4 }, { "hook": "static:app.load", "method": "init" }, { "hook": "filter:admin.header.build", "method": "buildMenu" } ], "staticDirs": { "static": "./static" } }
-
Yeah, just realised that... I'd better go back to my old strategy.
-
Yepp.. I convert it back after parsing manipulating the url.