mastercontroller 1.3.7 โ†’ 1.3.8

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.
@@ -13,7 +13,9 @@
13
13
  "Bash(node test-circular-dependency.js:*)",
14
14
  "Bash(/tmp/verify_fix.sh)",
15
15
  "Bash(node test-v1.3.4-fixes.js:*)",
16
- "Bash(npm install)"
16
+ "Bash(npm install)",
17
+ "Bash(node test-json-empty-body.js)",
18
+ "Bash(npm install:*)"
17
19
  ],
18
20
  "deny": [],
19
21
  "ask": []
package/MasterRequest.js CHANGED
@@ -335,6 +335,12 @@ class MasterRequest{
335
335
  request.on('end', () => {
336
336
  if (errorOccurred) return;
337
337
 
338
+ // Handle empty body (GET requests, etc.)
339
+ if (buffer.trim() === '') {
340
+ func({});
341
+ return;
342
+ }
343
+
338
344
  try {
339
345
  var buff = JSON.parse(buffer);
340
346
  func(buff);
@@ -0,0 +1,2 @@
1
+ {"timestamp":"2026-01-16T04:37:33.476Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_FRAMEWORK_START","message":"MasterController framework initializing","component":null,"file":null,"line":null,"route":null,"context":{"version":"1.0.247","nodeVersion":"v20.19.4","platform":"darwin","env":"development"},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46104576,"heapTotal":10027008,"heapUsed":5720488,"external":2111800,"arrayBuffers":65875},"uptime":0.022275917}
2
+ {"timestamp":"2026-01-16T04:37:33.477Z","sessionId":"1768538253474-z0w973cmg","level":"INFO","code":"MC_INFO_SECURITY_INITIALIZED","message":"Security features initialized","component":null,"file":null,"line":null,"route":null,"context":{"environment":"development","features":{"securityHeaders":true,"csp":true,"csrf":true,"rateLimit":true,"sessionSecurity":true}},"stack":null,"originalError":null,"environment":"development","nodeVersion":"v20.19.4","platform":"darwin","memory":{"rss":46186496,"heapTotal":10027008,"heapUsed":5729744,"external":2111840,"arrayBuffers":65875},"uptime":0.022643334}
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "dependencies": {
3
- "qs" : "^6.14.1",
4
- "formidable": "^3.5.4",
3
+ "content-type": "^1.0.5",
5
4
  "cookie": "^1.1.1",
6
- "winston": "^3.19.0",
7
- "glob" :"^13.0.0"
5
+ "formidable": "^3.5.4",
6
+ "glob": "^13.0.0",
7
+ "qs": "^6.14.1",
8
+ "winston": "^3.19.0"
8
9
  },
9
10
  "description": "A class library that makes using the Master Framework a breeze",
10
11
  "homepage": "https://github.com/Tailor/MasterController#readme",
@@ -18,5 +19,5 @@
18
19
  "scripts": {
19
20
  "test": "echo \"Error: no test specified\" && exit 1"
20
21
  },
21
- "version": "1.3.7"
22
- }
22
+ "version": "1.3.8"
23
+ }
@@ -0,0 +1,76 @@
1
+ // Test for JSON parsing bug fix - empty body on GET requests
2
+
3
+ const http = require('http');
4
+ const EventEmitter = require('events');
5
+
6
+ console.log('๐Ÿงช Testing MasterRequest jsonStream with empty body...\n');
7
+
8
+ // Load MasterRequest
9
+ const { MasterRequest } = require('./MasterRequest');
10
+
11
+ // Create mock request with empty body (simulates GET request)
12
+ class MockRequest extends EventEmitter {
13
+ constructor() {
14
+ super();
15
+ this.headers = {
16
+ 'content-type': 'application/json'
17
+ };
18
+ }
19
+
20
+ simulateEmptyBody() {
21
+ // Simulate empty body - no data events, just end
22
+ setImmediate(() => {
23
+ this.emit('end');
24
+ });
25
+ }
26
+ }
27
+
28
+ // Test 1: Empty body should not throw error
29
+ console.log('Test 1: Empty body (GET request scenario)...');
30
+ const masterRequest1 = new MasterRequest();
31
+ masterRequest1.init({ maxJsonSize: 1024 * 1024 });
32
+ const mockReq1 = new MockRequest();
33
+
34
+ masterRequest1.jsonStream(mockReq1, (result) => {
35
+ if (result && typeof result === 'object' && !result.error) {
36
+ console.log('โœ… Empty body handled correctly');
37
+ console.log(' Result:', JSON.stringify(result));
38
+
39
+ // Test 2: Valid JSON body
40
+ console.log('\nTest 2: Valid JSON body...');
41
+ const masterRequest2 = new MasterRequest();
42
+ masterRequest2.init({ maxJsonSize: 1024 * 1024 });
43
+ const mockReq2 = new MockRequest();
44
+
45
+ masterRequest2.jsonStream(mockReq2, (result) => {
46
+ if (result && result.name === 'test' && result.value === 123) {
47
+ console.log('โœ… Valid JSON parsed correctly');
48
+ console.log(' Result:', JSON.stringify(result));
49
+
50
+ console.log('\nโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
51
+ console.log('โœจ ALL TESTS PASSED');
52
+ console.log('โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”');
53
+ console.log('\nFix verified:');
54
+ console.log('โœ… Empty body returns {} instead of throwing error');
55
+ console.log('โœ… Valid JSON still parses correctly');
56
+ console.log('โœ… No more "Unexpected end of JSON input" errors on GET requests');
57
+ } else {
58
+ console.log('โŒ Valid JSON parsing failed');
59
+ console.log(' Result:', JSON.stringify(result));
60
+ }
61
+ });
62
+
63
+ // Simulate valid JSON body
64
+ setImmediate(() => {
65
+ mockReq2.emit('data', Buffer.from('{"name":"test","value":123}'));
66
+ mockReq2.emit('end');
67
+ });
68
+
69
+ } else {
70
+ console.log('โŒ Empty body test failed');
71
+ console.log(' Result:', JSON.stringify(result));
72
+ }
73
+ });
74
+
75
+ // Start test
76
+ mockReq1.simulateEmptyBody();