Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit b444fe0

Browse files
committed
Handles Plugin:ResourceURL wcm tags
1 parent 3652e64 commit b444fe0

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

digexp-sp-server/index.js

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ function doTagReplacement(contents) {
5252
var newContents = contents;
5353
for (var i = 0; i < tagsFound.length; i++) {
5454
var tag = tagsFound[i];
55-
newContents = newContents.replace(tag, getMockValue(tag, tagMap));
55+
if (tag.match(/Plugin:ResourceURL/)) {
56+
newContents = newContents.replace(tag, getResourceURL(tag));
57+
} else {
58+
newContents = newContents.replace(tag, getMockValue(tag, tagMap));
59+
}
5660
}
5761
for (var i = 0; i < endTagsFound.length; i++) {
5862
var tag = endTagsFound[i];
@@ -70,6 +74,34 @@ function getMockValue(tag, tagMap) {
7074
return "";
7175
}
7276

77+
/**
78+
* Replaces a Plugin:ResourceURL tag with the url being processed.
79+
* NOTE: this may fail for nested tags
80+
*/
81+
function getResourceURL(tag) {
82+
var url = tag.match(/url="[^"]*"/)[0] || 'url=""';
83+
url = url.substring('url="'.length, url.length - 1);
84+
85+
// Checks if the url has a query string but it doesn't verify correctness.
86+
var hasQueryString = url.match(/\?[\w-&=]*$/);
87+
var params = tag.match(/param="[^"]+"/g) || [];
88+
var start = 'param="'.length;
89+
params = params.map(function(param) { return param.substring(start, param.length - 1); })
90+
.join('&');
91+
92+
if (params) {
93+
url += hasQueryString ? '&' : '?';
94+
url += params;
95+
}
96+
97+
var proxy = !tag.match(/proxy="false"/);
98+
if (proxy) {
99+
return "/wps/proxy/" + url.replace(":/", "");
100+
} else {
101+
return url;
102+
}
103+
}
104+
73105
function findEndTag(substr) {
74106
var inQuotes = false;
75107
for (var i = 0, len = substr.length; i < len; i++) {

0 commit comments

Comments
 (0)