Project

General

Profile

Actions

Bug #3256

closed

JSON output by ?json query param is invalid

Added by titular.watcher0v 3 months ago. Updated 3 months ago.

Status:
Fixed
Priority:
Normal
Category:
mod_dirlisting
Target version:
ASK QUESTIONS IN Forums:
No

Description

Adding ?json to any directory results in the following JSON, when dirlisting is enabled:

{[{"name":"02","type":"dir","size":4096,"mtime":1704503997},{"name":"03","type":"dir","size":4096,"mtime":1704497695}]}

The curly bracket enclosing the list are not valid JSON.

Here are two valid alternatives:

[{"name":"02","type":"dir","size":4096,"mtime":1704503997},{"name":"03","type":"dir","size":4096,"mtime":1704497695}]
{"items":[{"name":"02","type":"dir","size":4096,"mtime":1704503997},{"name":"03","type":"dir","size":4096,"mtime":1704497695}]}

I prefer the first one: A list as the root element.

Actions #1

Updated by gstrauss 3 months ago

  • Status changed from New to Patch Pending
  • Target version changed from 1.4.xx to 1.4.77

Thanks for the report. This patch should fix it. I'll have to test this further on a variety of clients before committing.

--- a/src/mod_dirlisting.c
+++ b/src/mod_dirlisting.c
@@ -1581,7 +1581,7 @@ URIHANDLER_FUNC(mod_dirlisting_subrequest_start) {

        if (p->conf.json) {
                hctx->jb = chunk_buffer_acquire();
-               buffer_append_string_len(hctx->jb, CONST_STR_LEN("{["));
+               buffer_append_string_len(hctx->jb, CONST_STR_LEN("["));
                http_header_response_set(r, HTTP_HEADER_CONTENT_TYPE,
                                         CONST_STR_LEN("Content-Type"),
                                         CONST_STR_LEN("application/json"));
@@ -1645,7 +1645,7 @@ SUBREQUEST_FUNC(mod_dirlisting_subrequest) {
       case HANDLER_FINISHED:
         if (hctx->jb || hctx->hb) { /* (hctx->conf.json || !hctx->conf.sort) */
             if (hctx->jb)
-                buffer_append_string_len(hctx->jb, CONST_STR_LEN("]}"));
+                buffer_append_string_len(hctx->jb, CONST_STR_LEN("]"));
             mod_dirlisting_stream_append(r, hctx, 1);
             if (hctx->hb)
                 mod_dirlisting_cache_stream_add_footer(r, hctx);

Actions #2

Updated by gstrauss 3 months ago

  • Status changed from Patch Pending to Fixed
Actions

Also available in: Atom