@aimeloic/monkey-tester 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/htmlTemplate.js +16 -17
  2. package/package.json +1 -1
package/htmlTemplate.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export function getHtmlTemplate(endpoints) {
2
+ // Safe stringification for HTML attribute encoding
2
3
  const safeJsonString = Buffer.from(JSON.stringify(endpoints)).toString('base64');
3
4
 
4
5
  return `
@@ -148,13 +149,11 @@ function buildSidebar() {
148
149
  if (keys.length > 0) renderPanel(keys[0]);
149
150
  }
150
151
 
151
- function makeInput(type, id, placeholder, defaultValue) {
152
- var el = document.createElement('input');
153
- el.type = type;
154
- el.id = id;
155
- if (placeholder) el.placeholder = placeholder;
156
- if (defaultValue !== undefined) el.value = defaultValue;
157
- return el.outerHTML;
152
+ // FIXED: Elements are explicitly assigned attributes to enforce string literal values cleanly
153
+ function makeInputString(type, id, placeholder, defaultValue) {
154
+ const pAttr = placeholder ? ' placeholder="' + placeholder + '"' : '';
155
+ const vAttr = defaultValue !== undefined ? ' value=\'' + defaultValue + '\'' : '';
156
+ return '<input type="' + type + '" id="' + id + '"' + pAttr + vAttr + ' />';
158
157
  }
159
158
 
160
159
  function renderPanel(epKey) {
@@ -165,8 +164,8 @@ function renderPanel(epKey) {
165
164
 
166
165
  let html = '<div class="endpoint-title">' + ep.title + '</div>' +
167
166
  '<div class="endpoint-path">' +
168
- '<span class="method-badge ' + ep.method + '">' + ep.method + '</span>' +
169
- '<span>' + ep.path + '</span>' +
167
+ ' <span class="method-badge ' + ep.method + '">' + ep.method + '</span>' +
168
+ ' <span>' + ep.path + '</span>' +
170
169
  '</div>' +
171
170
  '<div class="endpoint-desc">' + ep.desc + '</div>';
172
171
 
@@ -174,8 +173,8 @@ function renderPanel(epKey) {
174
173
  html += '<div class="form-section"><div class="form-section-title">Path Parameters</div>';
175
174
  ep.params.forEach(function(p) {
176
175
  html += '<div class="field-row">' +
177
- '<label class="field-label">' + p.label + '</label>' +
178
- makeInput('text', 'param-' + p.name, p.placeholder, '') +
176
+ ' <label class="field-label">' + p.label + '</label>' +
177
+ makeInputString('text', 'param-' + p.name, p.placeholder, '') +
179
178
  '</div>';
180
179
  });
181
180
  html += '</div>';
@@ -185,16 +184,16 @@ function renderPanel(epKey) {
185
184
  html += '<div class="form-section"><div class="form-section-title">JSON Request Body Raw Payload</div>';
186
185
  ep.fields.forEach(function(f) {
187
186
  html += '<div class="field-row">' +
188
- '<label class="field-label">' + f.label + '</label>' +
189
- makeInput('text', 'field-' + f.name, '', '{"key": "value"}') +
187
+ ' <label class="field-label">' + f.label + '</label>' +
188
+ makeInputString('text', 'field-' + f.name, '', '{"key": "value"}') +
190
189
  '</div>';
191
190
  });
192
191
  html += '</div>';
193
192
  }
194
193
 
195
194
  html += '<div class="btn-row">' +
196
- '<button class="btn" onclick="sendRequest()">Execute Route</button>' +
197
- '<button class="btn btn-secondary" onclick="clearResponse()">Clear Context</button>' +
195
+ ' <button class="btn" onclick="sendRequest()">Execute Route</button>' +
196
+ ' <button class="btn btn-secondary" onclick="clearResponse()">Clear Context</button>' +
198
197
  '</div>';
199
198
 
200
199
  main.innerHTML = html;
@@ -212,7 +211,7 @@ async function sendRequest() {
212
211
  }
213
212
  }
214
213
 
215
- const baseUrl = document.getElementById('base-url').value.replace(/\/+$/, '');
214
+ const baseUrl = document.getElementById('base-url').value.replace(/[/]+$/, '');
216
215
  const url = baseUrl + path;
217
216
  const headers = { 'Content-Type': 'application/json' };
218
217
 
@@ -274,7 +273,7 @@ function clearResponse() {
274
273
 
275
274
  function highlightJson(str) {
276
275
  return str
277
- .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
276
+ .replace(/&/g, '&amp;').replace(/[<]/g, '&lt;').replace(/[>]/g, '&gt;')
278
277
  .replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function(match) {
279
278
  if (/^"/.test(match)) {
280
279
  if (/:$/.test(match)) return '<span class="json-key">' + match + '</span>';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aimeloic/monkey-tester",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Embedded interactive API testing UI for Node.js backends",
5
5
  "main": "index.js",
6
6
  "type":"module",