leptris 1.9.458.0-arm-linux → 1.9.460.0-arm-linux

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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/CONTEXT.md +9 -3
  4. data/README.adoc +28 -17
  5. data/Rakefile +1 -1
  6. data/lib/leptris/version.rb +1 -1
  7. data/lib/leptris/xml/document.rb +75 -48
  8. data/lib/leptris/xml/ffi.rb +8 -0
  9. data/lib/libleptris.so +0 -0
  10. data/vendor-src/README.md +1 -1
  11. data/vendor-src/libleptris/CHANGELOG.md +42 -0
  12. data/vendor-src/libleptris/CMakeLists.txt +1 -1
  13. data/vendor-src/libleptris/README.adoc +19 -0
  14. data/vendor-src/libleptris/benchmarks/CMakeLists.txt +23 -2
  15. data/vendor-src/libleptris/benchmarks/README.adoc +15 -0
  16. data/vendor-src/libleptris/benchmarks/README.md +17 -4
  17. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_decomp.cpp +2 -1
  18. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_first_access.cpp +2 -1
  19. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_many_attrs.cpp +2 -1
  20. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_memory.cpp +2 -1
  21. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse.cpp +2 -2
  22. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_parse_ops.cpp +8 -4
  23. data/vendor-src/libleptris/benchmarks/comprehensive/benchmark_write.cpp +4 -2
  24. data/vendor-src/libleptris/benchmarks/dom/dom_benchmark_v2.cpp +8 -4
  25. data/vendor-src/libleptris/benchmarks/fixtures/serialbench_users_medium.xml +13004 -0
  26. data/vendor-src/libleptris/benchmarks/matrix/bench_matrix.cpp +21 -76
  27. data/vendor-src/libleptris/benchmarks/matrix/bench_matrix_fused.cpp +31 -0
  28. data/vendor-src/libleptris/benchmarks/matrix/bench_rows.h +94 -0
  29. data/vendor-src/libleptris/benchmarks/modification/bench_append_attr_pugixml.cpp +2 -1
  30. data/vendor-src/libleptris/benchmarks/parse/bench_parse_ab.cpp +2 -1
  31. data/vendor-src/libleptris/benchmarks/twins/generation_users.sh +49 -0
  32. data/vendor-src/libleptris/benchmarks/twins/generation_users_fixture.h +78 -0
  33. data/vendor-src/libleptris/benchmarks/twins/generation_users_leptris.c +122 -0
  34. data/vendor-src/libleptris/benchmarks/twins/generation_users_pugixml.cpp +231 -0
  35. data/vendor-src/libleptris/benchmarks/twins/parse_pugixml.cpp +1 -1
  36. data/vendor-src/libleptris/benchmarks/twins/parse_users_ab.cpp +158 -0
  37. data/vendor-src/libleptris/benchmarks/workflows/bench_pipeline_shapes.cpp +12 -4
  38. data/vendor-src/libleptris/benchmarks/xpath/bench_pugixml.cpp +2 -1
  39. data/vendor-src/libleptris/cli/CLI_ARCHITECTURE.md +9 -1
  40. data/vendor-src/libleptris/cli/commands/diff.c +26 -28
  41. data/vendor-src/libleptris/cli/commands/format.c +3 -1
  42. data/vendor-src/libleptris/cli/commands/parse.c +3 -1
  43. data/vendor-src/libleptris/cli/commands/validate.c +22 -24
  44. data/vendor-src/libleptris/cli/commands/xpath.c +9 -1
  45. data/vendor-src/libleptris/cli/commands/xquery.c +12 -3
  46. data/vendor-src/libleptris/cli/commands/xslt.c +24 -8
  47. data/vendor-src/libleptris/cli/error.c +91 -0
  48. data/vendor-src/libleptris/cli/error.h +84 -0
  49. data/vendor-src/libleptris/cli/man/leptris-parse.1.adoc +21 -10
  50. data/vendor-src/libleptris/cli/man/leptris.1.adoc +19 -0
  51. data/vendor-src/libleptris/cli/output.c +18 -9
  52. data/vendor-src/libleptris/cli/output.h +17 -0
  53. data/vendor-src/libleptris/src/CMakeLists.txt +3 -0
  54. data/vendor-src/libleptris/src/include/leptris/types.h +25 -1
  55. data/vendor-src/libleptris/src/include/leptris/xquery/xquery.h +9 -1
  56. data/vendor-src/libleptris/src/include/leptris.h +48 -3
  57. data/vendor-src/libleptris/src/leptris/common/entities.c +2 -2
  58. data/vendor-src/libleptris/src/leptris/common/entities.h +8 -2
  59. data/vendor-src/libleptris/src/leptris/common/port.h +62 -0
  60. data/vendor-src/libleptris/src/leptris/common/uri_base.c +284 -0
  61. data/vendor-src/libleptris/src/leptris/common/uri_base.h +62 -0
  62. data/vendor-src/libleptris/src/leptris/core.c +33 -2
  63. data/vendor-src/libleptris/src/leptris/dom/compact.h +51 -0
  64. data/vendor-src/libleptris/src/leptris/dom/element.c +18 -0
  65. data/vendor-src/libleptris/src/leptris/dom/element.h +201 -12
  66. data/vendor-src/libleptris/src/leptris/dom/element_modify.c +611 -210
  67. data/vendor-src/libleptris/src/leptris/dom/element_query.c +72 -1
  68. data/vendor-src/libleptris/src/leptris/dom/name_intern.c +3 -1
  69. data/vendor-src/libleptris/src/leptris/dtd/model.c +13 -0
  70. data/vendor-src/libleptris/src/leptris/dtd/model.h +95 -6
  71. data/vendor-src/libleptris/src/leptris/dtd/resolver.c +302 -215
  72. data/vendor-src/libleptris/src/leptris/flat/direct_parse.c +801 -294
  73. data/vendor-src/libleptris/src/leptris/leptris.c +20 -5
  74. data/vendor-src/libleptris/src/leptris/leptris_internal.h +68 -22
  75. data/vendor-src/libleptris/src/leptris/serialize/serialize.c +289 -57
  76. data/vendor-src/libleptris/src/leptris/xinclude/xinclude.c +14 -125
  77. data/vendor-src/libleptris/src/leptris/xpath/evaluator.c +3 -0
  78. data/vendor-src/libleptris/src/leptris/xpath/evaluator_path.c +11 -8
  79. data/vendor-src/libleptris/src/leptris/xpath/functions_ext31.c +188 -24
  80. data/vendor-src/libleptris/src/leptris/xpath/vm.c +3 -1
  81. data/vendor-src/libleptris/src/leptris/xquery/xquery.c +5 -0
  82. data/vendor-src/libleptris/src/leptris/xsd/compile.c +59 -20
  83. data/vendor-src/libleptris/src/leptris/xsd/validate.c +291 -168
  84. data/vendor-src/libleptris/test/CMakeLists.txt +28 -0
  85. data/vendor-src/libleptris/test/abi/test_public_surface.cpp +37 -0
  86. data/vendor-src/libleptris/test/cli/test_cli.cpp +228 -0
  87. data/vendor-src/libleptris/test/common/hang_guard.h +179 -0
  88. data/vendor-src/libleptris/test/dom/test_compact.cpp +46 -0
  89. data/vendor-src/libleptris/test/dom/test_mut_append_contracts.cpp +173 -0
  90. data/vendor-src/libleptris/test/dom/test_mut_set_attr_contracts.cpp +771 -7
  91. data/vendor-src/libleptris/test/fixtures/entity_limits/good.xml +100 -0
  92. data/vendor-src/libleptris/test/fixtures/entity_limits/good_attr.xml +100 -0
  93. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_classic.xml +51 -0
  94. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_attr.xml +23 -0
  95. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_ig_content.xml +23 -0
  96. data/vendor-src/libleptris/test/fixtures/entity_limits/lol_long_name.xml +23 -0
  97. data/vendor-src/libleptris/test/memory/test_oom_injection.cpp +63 -0
  98. data/vendor-src/libleptris/test/parser/test_entity_limits.cpp +404 -0
  99. data/vendor-src/libleptris/test/parser/test_parser.cpp +126 -0
  100. data/vendor-src/libleptris/test/serializer/test_serialize.cpp +491 -0
  101. data/vendor-src/libleptris/test/xpath/test_base_uri.cpp +368 -0
  102. data/vendor-src/libleptris/test/xpath/test_xpath.cpp +86 -0
  103. data/vendor-src/libleptris/test/xsd/test_xsd11_base_uri.cpp +145 -0
  104. data/vendor-src/libleptris/test/xsd/test_xsd11_conformance.cpp +23 -5
  105. data/vendor-src/libleptris/test/xsd/test_xsd11_cta_context.cpp +385 -0
  106. data/vendor-src/libleptris/test/xsd/xsd11-all/all-restrict.xsd +3 -2
  107. data/vendor-src/libleptris/test/xsd/xsd11-all/all-wildcard.xsd +3 -2
  108. data/vendor-src/libleptris/test/xsd/xsd11-cases/MANIFEST.tsv +19 -2
  109. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.n01.xml +5 -0
  110. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.v01.xml +4 -0
  111. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0003.xsd +46 -0
  112. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.v01.xml +6 -0
  113. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0006.xsd +83 -0
  114. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.v01.xml +3 -0
  115. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0017.xsd +36 -0
  116. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.n01.xml +3 -0
  117. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.v01.xml +3 -0
  118. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0021.xsd +36 -0
  119. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0023.v01.xml +3 -0
  120. data/vendor-src/libleptris/test/xsd/xsd11-cases/saxonData/CTA/cta0024.xsd +40 -0
  121. data/vendor-src/libleptris/test/xsd/xsd11-dispositions/README.md +67 -0
  122. data/vendor-src/libleptris/vcpkg.json +1 -1
  123. metadata +35 -2
@@ -98,10 +98,19 @@ static cli_result_t xquery_run(int argc, char** argv) {
98
98
  cli_result_t rc = CLI_SUCCESS;
99
99
  LeptrisDocument doc = NULL;
100
100
  if (opts.source_file) {
101
- doc = leptris_parse_file(opts.source_file, NULL);
101
+ LeptrisStatus src_status = LEPTRIS_OK;
102
+ doc = leptris_parse_file(opts.source_file, &src_status);
102
103
  if (!doc) {
103
- cli_error("cannot parse source document: %s",
104
- opts.source_file);
104
+ /* An unreadable source is an I/O report; a parse failure
105
+ * carries the engine's diagnostic (#2291). */
106
+ if (src_status == LEPTRIS_ERROR_NOT_FOUND ||
107
+ src_status == LEPTRIS_ERROR_IO) {
108
+ cli_error("cannot read source document: %s",
109
+ opts.source_file);
110
+ } else {
111
+ cli_error_engine(opts.source_file, src_status,
112
+ OUTPUT_FORMAT_TEXT);
113
+ }
105
114
  leptris_xquery_free(xq);
106
115
  return CLI_ERROR_PARSE;
107
116
  }
@@ -23,13 +23,21 @@ typedef struct {
23
23
  const char* input;
24
24
  } xslt_options_t;
25
25
 
26
- static LeptrisDocument load_input(const char* input) {
26
+ /* Load the input document (a path, or stdin for "-"/absent). NULL with
27
+ * *status NOT_FOUND / IO = the input could not be read; NULL with any
28
+ * other status = a parse failure, whose engine diagnostic sits on the
29
+ * public error channel for the caller to report (#2291). */
30
+ static LeptrisDocument load_input(const char* input, LeptrisStatus* status) {
31
+ *status = LEPTRIS_OK;
27
32
  if (input && strcmp(input, "-") != 0)
28
- return leptris_parse_file(input, NULL);
33
+ return leptris_parse_file(input, status);
29
34
  size_t len = 0;
30
35
  char* xml = cli_read_file("-", &len);
31
- if (!xml) return NULL;
32
- LeptrisDocument doc = leptris_parse_string(xml, len, NULL);
36
+ if (!xml) {
37
+ *status = LEPTRIS_ERROR_IO;
38
+ return NULL;
39
+ }
40
+ LeptrisDocument doc = leptris_parse_string(xml, len, status);
33
41
  free(xml);
34
42
  return doc;
35
43
  }
@@ -73,11 +81,19 @@ static cli_result_t xslt_run(int argc, char** argv) {
73
81
  return CLI_ERROR_PARSE;
74
82
  }
75
83
 
76
- LeptrisDocument doc = load_input(opts.input);
84
+ LeptrisStatus input_status = LEPTRIS_OK;
85
+ LeptrisDocument doc = load_input(opts.input, &input_status);
77
86
  if (!doc) {
78
- cli_error("cannot parse input document: %s: %s",
79
- opts.input ? opts.input : "(empty)",
80
- leptris_last_error());
87
+ /* Absent input means stdin: name it "-" like every other
88
+ * command. An unreadable input is an I/O report; a parse
89
+ * failure carries the engine's diagnostic (#2291). */
90
+ const char* name = opts.input ? opts.input : "-";
91
+ if (input_status == LEPTRIS_ERROR_NOT_FOUND ||
92
+ input_status == LEPTRIS_ERROR_IO) {
93
+ cli_error("cannot read input document: %s", name);
94
+ } else {
95
+ cli_error_engine(name, input_status, OUTPUT_FORMAT_TEXT);
96
+ }
81
97
  leptris_xslt_free(sheet);
82
98
  return CLI_ERROR_PARSE;
83
99
  }
@@ -312,6 +312,97 @@ void cli_error_usage(const char* command, const char* message) {
312
312
  g_error_stats.error_count++;
313
313
  }
314
314
 
315
+ /* ------------------------------------------------------------------------- */
316
+ /* Engine diagnostics (#2291) */
317
+ /* ------------------------------------------------------------------------- */
318
+
319
+ void cli_engine_error_capture(cli_engine_error_t* error,
320
+ const char* file,
321
+ LeptrisStatus status) {
322
+ if (!error) return;
323
+
324
+ int line = 0, column = 0;
325
+ leptris_last_error_position(&line, &column);
326
+ const char* message = leptris_last_error();
327
+
328
+ error->status = status;
329
+ /* The status string is the API's own text for the code — the
330
+ * fallback for a path that left the channel empty. */
331
+ error->message = message ? message : leptris_status_string(status);
332
+ error->file = file;
333
+ error->line = line;
334
+ error->column = column;
335
+ }
336
+
337
+ /* Shared position prefix: "file:line:col: " with the fields the error
338
+ * actually carries (file omitted when NULL, line/column when 0). */
339
+ static void print_engine_location(const cli_engine_error_t* error,
340
+ FILE* out) {
341
+ if (!error->file) return;
342
+
343
+ fputs(error->file, out);
344
+ if (error->line > 0) {
345
+ fprintf(out, ":%d", error->line);
346
+ if (error->column > 0) {
347
+ fprintf(out, ":%d", error->column);
348
+ }
349
+ }
350
+ fputs(": ", out);
351
+ }
352
+
353
+ void cli_error_print_engine(const cli_engine_error_t* error) {
354
+ if (!error) return;
355
+
356
+ ensure_streams_initialized();
357
+
358
+ FILE* out = g_error_config.error_stream;
359
+ print_engine_location(error, out);
360
+ fprintf(out, "%serror:%s %s\n",
361
+ get_color_code(ERROR_LEVEL_ERROR),
362
+ get_reset_code(),
363
+ error->message);
364
+
365
+ g_error_stats.error_count++;
366
+ }
367
+
368
+ void cli_error_print_engine_json(const cli_engine_error_t* error) {
369
+ if (!error) return;
370
+
371
+ ensure_streams_initialized();
372
+
373
+ FILE* out = g_error_config.error_stream;
374
+ fputs("{\"error\":{\"message\":\"", out);
375
+ output_json_escape_string(error->message, out);
376
+ fprintf(out, "\",\"code\":%d", (int)error->status);
377
+ if (error->file) {
378
+ fputs(",\"file\":\"", out);
379
+ output_json_escape_string(error->file, out);
380
+ fputc('"', out);
381
+ }
382
+ if (error->line > 0) {
383
+ fprintf(out, ",\"line\":%d", error->line);
384
+ if (error->column > 0) {
385
+ fprintf(out, ",\"column\":%d", error->column);
386
+ }
387
+ }
388
+ fputs("}}\n", out);
389
+
390
+ g_error_stats.error_count++;
391
+ }
392
+
393
+ void cli_error_engine(const char* file,
394
+ LeptrisStatus status,
395
+ output_format_t format) {
396
+ cli_engine_error_t error;
397
+ cli_engine_error_capture(&error, file, status);
398
+
399
+ if (format == OUTPUT_FORMAT_JSON) {
400
+ cli_error_print_engine_json(&error);
401
+ } else {
402
+ cli_error_print_engine(&error);
403
+ }
404
+ }
405
+
315
406
  /* ------------------------------------------------------------------------- */
316
407
  /* Global Configuration */
317
408
  /* ------------------------------------------------------------------------- */
@@ -29,6 +29,13 @@
29
29
  #include <stdarg.h>
30
30
  #include <stdbool.h>
31
31
 
32
+ /* Engine diagnostics (#2291) render in the command's output format and
33
+ * read the public error channel: output.h for the format enum, the
34
+ * public headers for LeptrisStatus / leptris_last_error. */
35
+ #include "output.h"
36
+ #include "leptris.h"
37
+ #include "leptris/error.h"
38
+
32
39
  #ifdef __cplusplus
33
40
  extern "C" {
34
41
  #endif
@@ -253,6 +260,83 @@ void cli_error_usage(
253
260
  const char* message
254
261
  );
255
262
 
263
+ /* ------------------------------------------------------------------------- */
264
+ /* Engine diagnostics (#2291) */
265
+ /* ------------------------------------------------------------------------- */
266
+
267
+ /**
268
+ * One failed engine operation, as the public error API reports it
269
+ *
270
+ * Captured right after the failing call: the status out-param carries
271
+ * the code, leptris_last_error() the message and
272
+ * leptris_last_error_position() the position. Both channels are
273
+ * thread-local, which matches the CLI's one-operation-per-process
274
+ * model; capture before any other engine call on the thread.
275
+ */
276
+ typedef struct cli_engine_error {
277
+ LeptrisStatus status; /**< Status the failing call returned */
278
+ const char* message; /**< Engine message (never NULL, see cli_engine_error_capture) */
279
+ const char* file; /**< Input as the user spelled it ("-" for stdin), or NULL */
280
+ int line; /**< 1-based line, 0 when the engine recorded none */
281
+ int column; /**< 1-based column, 0 when the engine recorded none */
282
+ } cli_engine_error_t;
283
+
284
+ /**
285
+ * Capture the engine's diagnostic for a failed operation
286
+ *
287
+ * Reads leptris_last_error() / leptris_last_error_position(). When the
288
+ * engine recorded no message for the failure, the message is
289
+ * leptris_status_string(status) — the API's own text for the code,
290
+ * never a CLI-invented diagnostic (an engine gap is reported upstream,
291
+ * not papered over here).
292
+ *
293
+ * @param error Out: captured diagnostic
294
+ * @param file Input path as the user spelled it (may be NULL)
295
+ * @param status Status the failing call returned
296
+ */
297
+ void cli_engine_error_capture(cli_engine_error_t* error,
298
+ const char* file,
299
+ LeptrisStatus status);
300
+
301
+ /**
302
+ * Print an engine diagnostic — compiler-style text line
303
+ *
304
+ * file:line:col: error: message
305
+ *
306
+ * Position fields are omitted when the engine recorded none (line 0);
307
+ * the file is omitted when NULL. Goes to the error stream.
308
+ *
309
+ * @param error Captured diagnostic
310
+ */
311
+ void cli_error_print_engine(const cli_engine_error_t* error);
312
+
313
+ /**
314
+ * Print an engine diagnostic — JSON object (OUTPUT_FORMAT_JSON)
315
+ *
316
+ * {"error":{"message":"...","code":-2,"file":"-","line":1,"column":11}}
317
+ *
318
+ * Same omission rule as the text line. Goes to the error stream so a
319
+ * consumer's stdout stays the result channel.
320
+ *
321
+ * @param error Captured diagnostic
322
+ */
323
+ void cli_error_print_engine_json(const cli_engine_error_t* error);
324
+
325
+ /**
326
+ * Report a failed engine operation in the command's output format
327
+ *
328
+ * JSON renders the structured object; XML and text render the
329
+ * compiler-style line — a format never mixes shapes (MECE). The
330
+ * message prints regardless of verbosity: the reason IS the error.
331
+ *
332
+ * @param file Input path as the user spelled it (may be NULL)
333
+ * @param status Status the failing call returned
334
+ * @param format Command output format
335
+ */
336
+ void cli_error_engine(const char* file,
337
+ LeptrisStatus status,
338
+ output_format_t format);
339
+
256
340
  /* ------------------------------------------------------------------------- */
257
341
  /* Global Error State */
258
342
  /* ------------------------------------------------------------------------- */
@@ -160,21 +160,32 @@ fi
160
160
 
161
161
  == ERROR HANDLING
162
162
 
163
- When parsing fails, *leptris parse* provides detailed error messages including:
163
+ When parsing fails, *leptris parse* prints the parser's own diagnostic —
164
+ the message and position the library reports for the failure — on
165
+ standard error. The reason is the error itself: it prints with or without
166
+ *--verbose*, which only adds document details after a _successful_ parse.
164
167
 
165
- * Line and column numbers where the error occurred
166
- * Description of the syntax error
167
- * Context snippet showing the problematic area
168
+ In the *xml* and *text* output formats the diagnostic is a compiler-style
169
+ line, `FILE:LINE:COLUMN: error: MESSAGE` (the position when the parser
170
+ recorded one, *-* for standard input):
168
171
 
169
- Example error output:
170
172
  ----
171
- Error: Parse error at line 5, column 12
172
- Unclosed tag 'book'
173
- <book>
174
- <title>Example
175
- ----------^
173
+ $ echo '<a><b></a></b>' | leptris parse -
174
+ -:1:11: error: XML parse error at byte 10: Opening and ending tag mismatch: expected </b>, got </a>
176
175
  ----
177
176
 
177
+ In the *json* output format the diagnostic is a structured object
178
+ (`message`, the numeric `code`, and the `file`/`line`/`column` the parser
179
+ recorded), so scripts can read the failure without parsing prose:
180
+
181
+ ----
182
+ $ echo '<a><b></a></b>' | leptris parse --format json -
183
+ {"error":{"message":"XML parse error at byte 10: Opening and ending tag mismatch: expected </b>, got </a>","code":-2,"file":"-","line":1,"column":11}}
184
+ ----
185
+
186
+ An input that cannot be read at all is reported as an I/O error instead
187
+ (`cannot read file: FILE: REASON`, exit status 3).
188
+
178
189
  == SEE ALSO
179
190
 
180
191
  *leptris*(1), *leptris-xpath*(1), *leptris-format*(1), *libleptris*(5)
@@ -111,6 +111,25 @@ leptris version
111
111
  *6*::
112
112
  Internal error - unexpected condition (please report as bug)
113
113
 
114
+ == DIAGNOSTICS
115
+
116
+ Every command reports a failed parse of its input on standard error with
117
+ the library's own diagnostic — the message, and the line and column when
118
+ the parser recorded one — never a generic "failed" line. The reason is the
119
+ error itself: it is printed with or without *--verbose*.
120
+
121
+ In the *xml* and *text* output formats the diagnostic is a compiler-style
122
+ line, `FILE:LINE:COLUMN: error: MESSAGE` (*-* names standard input). In
123
+ the *json* output format it is a structured object with the `message`, the
124
+ numeric `code` and the recorded `file`/`line`/`column`:
125
+
126
+ ----
127
+ $ leptris parse --format json bad.xml
128
+ {"error":{"message":"XML parse error at byte 10: Opening and ending tag mismatch: expected </b>, got </a>","code":-2,"file":"bad.xml","line":1,"column":11}}
129
+ ----
130
+
131
+ An input that cannot be read at all is an I/O error (exit status 3).
132
+
114
133
  == ENVIRONMENT
115
134
 
116
135
  *LEPTRIS_LOG_LEVEL*::
@@ -409,7 +409,7 @@ static output_formatter_t* create_xml_formatter(void) {
409
409
  /* JSON Formatter */
410
410
  /* ------------------------------------------------------------------------- */
411
411
 
412
- static void json_escape_string(const char* str, FILE* out) {
412
+ void output_json_escape_string(const char* str, FILE* out) {
413
413
  if (!str) return;
414
414
  for (const char* p = str; *p; p++) {
415
415
  switch (*p) {
@@ -420,7 +420,16 @@ static void json_escape_string(const char* str, FILE* out) {
420
420
  case '\n': fprintf(out, "\\n"); break;
421
421
  case '\r': fprintf(out, "\\r"); break;
422
422
  case '\t': fprintf(out, "\\t"); break;
423
- default: fputc(*p, out); break;
423
+ /* Other C0 controls (an engine message may quote input
424
+ * bytes) have no JSON short escape — \u00XX keeps the
425
+ * document valid. */
426
+ default:
427
+ if ((unsigned char)*p < 0x20) {
428
+ fprintf(out, "\\u%04x", (unsigned char)*p);
429
+ } else {
430
+ fputc(*p, out);
431
+ }
432
+ break;
424
433
  }
425
434
  }
426
435
  }
@@ -437,7 +446,7 @@ static void json_print_element_recursive(
437
446
  /* Element name - use API */
438
447
  const char* name = leptris_element_name(elem);
439
448
  fprintf(out, "\"name\":\"");
440
- json_escape_string(name ? name : "", out);
449
+ output_json_escape_string(name ? name : "", out);
441
450
  fprintf(out, "\"");
442
451
 
443
452
  /* Attributes - public handle iteration */
@@ -454,10 +463,10 @@ static void json_print_element_recursive(
454
463
  first_attr = 0;
455
464
 
456
465
  fprintf(out, "\"");
457
- json_escape_string(attr_name, out);
466
+ output_json_escape_string(attr_name, out);
458
467
  fprintf(out, "\":\"");
459
468
  if (attr_value) {
460
- json_escape_string(attr_value, out);
469
+ output_json_escape_string(attr_value, out);
461
470
  }
462
471
  fprintf(out, "\"");
463
472
  }
@@ -470,7 +479,7 @@ static void json_print_element_recursive(
470
479
  const char* text_content = leptris_element_text(elem);
471
480
  if (text_content && text_content[0] != '\0') {
472
481
  fprintf(out, ",\"text\":\"");
473
- json_escape_string(text_content, out);
482
+ output_json_escape_string(text_content, out);
474
483
  fprintf(out, "\"");
475
484
  }
476
485
 
@@ -539,13 +548,13 @@ static void json_print_nodeset_impl(
539
548
  fprintf(out, "{\"");
540
549
  const char* name = leptris_xpath_result_node_name(result, i);
541
550
  if (name) {
542
- json_escape_string(name, out);
551
+ output_json_escape_string(name, out);
543
552
  }
544
553
  fprintf(out, "\":");
545
554
  const char* value = leptris_xpath_result_node_value(result, i);
546
555
  if (value) {
547
556
  fprintf(out, "\"");
548
- json_escape_string(value, out);
557
+ output_json_escape_string(value, out);
549
558
  fprintf(out, "\"");
550
559
  } else {
551
560
  fprintf(out, "null");
@@ -555,7 +564,7 @@ static void json_print_nodeset_impl(
555
564
  const char* content = leptris_xpath_result_node_value(result, i);
556
565
  if (content) {
557
566
  fprintf(out, "\"");
558
- json_escape_string(content, out);
567
+ output_json_escape_string(content, out);
559
568
  fprintf(out, "\"");
560
569
  } else {
561
570
  fprintf(out, "null");
@@ -207,6 +207,23 @@ output_formatter_t* output_formatter_create(output_format_t type);
207
207
  */
208
208
  void output_formatter_free(output_formatter_t* fmt);
209
209
 
210
+ /* ------------------------------------------------------------------------- */
211
+ /* JSON writer */
212
+ /* ------------------------------------------------------------------------- */
213
+
214
+ /**
215
+ * Write a string as a JSON string body (without the enclosing quotes)
216
+ *
217
+ * The one JSON escaper in the CLI: the JSON formatter's document and
218
+ * nodeset writers and the structured error object (error.c) all go
219
+ * through it, so a format never grows a second spelling of the same
220
+ * escaping rules.
221
+ *
222
+ * @param str String to escape (NULL writes nothing)
223
+ * @param out Output stream
224
+ */
225
+ void output_json_escape_string(const char* str, FILE* out);
226
+
210
227
  /* ------------------------------------------------------------------------- */
211
228
  /* Format-Specific Options */
212
229
  /* ------------------------------------------------------------------------- */
@@ -63,6 +63,9 @@ set(LEPTRIS_SOURCES
63
63
  # Common utilities
64
64
  leptris/common/string_view.c
65
65
  leptris/common/format_number.c
66
+ # #2278: RFC 3986 base-URI algebra (XInclude xml:base, fn:base-uri,
67
+ # fn:doc's static-base resolution, the document URI)
68
+ leptris/common/uri_base.c
66
69
  leptris/common/entities.c
67
70
  leptris/common/chartype.c
68
71
  # AOT SIMD framework (TODO 175): scalar impls + runtime dispatch
@@ -250,7 +250,31 @@ typedef enum {
250
250
  * token stream as diagnostics (code + line + column) on the
251
251
  * HTML parse — the lint layer validators need. Opt-in: the
252
252
  * tree construction stays exactly as fast without it. */
253
- LEPTRIS_PARSE_COLLECT_HTML_ERRORS = 64u
253
+ LEPTRIS_PARSE_COLLECT_HTML_ERRORS = 64u,
254
+ /* leptris#2281: lift the entity-expansion resource limits (the
255
+ * "billion laughs" / CAPEC-197 guard) for trusted documents that
256
+ * legitimately need huge expansion — libxml2's XML_PARSE_HUGE
257
+ * posture. OFF by default; with the limits ON the parse FAILS
258
+ * (status LEPTRIS_ERROR_PARSE, leptris_last_error naming the
259
+ * limit) the moment an expansion breaches any of:
260
+ * - nesting depth : 20 nested general entities (40 with
261
+ * this flag) — libxml2's entity maxDepth;
262
+ * - one expanded text node / attribute value: 10,000,000 bytes
263
+ * (XML_MAX_TEXT_LENGTH; lifted);
264
+ * - total expansion : output bytes + 20 bytes per reference
265
+ * may not exceed max(1,000,000 bytes,
266
+ * 5 x the input size) — XML_PARSER_
267
+ * ALLOWED_EXPANSION / XML_MAX_AMPLIFI-
268
+ * CATION_DEFAULT / XML_ENT_FIXED_COST
269
+ * (lifted);
270
+ * - reference count : the same budget at the 20-byte fixed
271
+ * cost — 50,000 references for inputs
272
+ * under 200 KB, scaling with the input
273
+ * (lifted).
274
+ * Predefined entities (&amp; &lt; ...) never count. The limits are
275
+ * per parse: every text node and attribute value of the document
276
+ * shares one budget. */
277
+ LEPTRIS_PARSE_ALLOW_HUGE_EXPANSION = 128u
254
278
  } LeptrisParseFlags;
255
279
 
256
280
  /* ============================================================================
@@ -85,7 +85,15 @@ typedef enum {
85
85
  * validated element and its subtree — '/' and '//' reach for
86
86
  * a document root the model does not contain and select
87
87
  * NOTHING (d4_3_15ii14/ii31 pin both directions). */
88
- LEPTRIS_XQUERY_ASSERT_ROOTED = 4
88
+ LEPTRIS_XQUERY_ASSERT_ROOTED = 4,
89
+ /* XSD 1.1 §3.12.4 CTA {test} data model (#2277): the context
90
+ * element is the ROOT NODE of the data model — "the root node of
91
+ * the instance is necessarily constructed from E" — so fn:root
92
+ * answers the context element (its first ancestor-or-self without
93
+ * a parent) instead of the document node of the document that
94
+ * carries it. The caller supplies the parentless, childless copy
95
+ * of E as the context node. */
96
+ LEPTRIS_XQUERY_CONTEXT_IS_ROOT = 8
89
97
  } LeptrisXQueryEvalFlag;
90
98
 
91
99
  /* leptris_xquery_eval_params with evaluation-context flags (XSD
@@ -1194,6 +1194,10 @@ LEPTRIS_API char* leptris_load_file(const char* filepath, size_t* out_size);
1194
1194
  * Parse XML file directly
1195
1195
  *
1196
1196
  * Convenience function that loads a file and parses it as XML.
1197
+ * The resolved path (absolute, lexically normalized) is recorded as
1198
+ * the document URI (#2278) — read back with leptris_document_uri();
1199
+ * it is what fn:base-uri()/fn:document-uri()/fn:static-base-uri()
1200
+ * answer for the document's nodes.
1197
1201
  *
1198
1202
  * @param filepath Path to XML file to parse
1199
1203
  * @param status Output status code (can be NULL)
@@ -1350,6 +1354,40 @@ LEPTRIS_API LeptrisStatus leptris_document_set_encoding(
1350
1354
  LEPTRIS_API LeptrisStatus leptris_document_set_standalone(
1351
1355
  LeptrisDocument doc, int standalone);
1352
1356
 
1357
+ /**
1358
+ * Document URI (#2278) — the document's base/document URI.
1359
+ *
1360
+ * leptris_parse_file() records the resolved path (absolute,
1361
+ * lexically normalized) as the document URI; an in-memory parse
1362
+ * (leptris_parse_string and friends) carries NONE until the caller
1363
+ * sets one with leptris_document_set_uri() — the libxml2
1364
+ * xmlReadMemory(buf, size, url, ...) / Nokogiri Document.parse(
1365
+ * string, url) shape. Plain path/URL form, exactly as supplied.
1366
+ *
1367
+ * This is the document-uri property fn:document-uri() answers and
1368
+ * the root fn:base-uri() resolves xml:base against; it is also the
1369
+ * standalone XPath engine's static base URI.
1370
+ *
1371
+ * @param doc Document
1372
+ * @return The URI string, or NULL when the document has none
1373
+ *
1374
+ * Memory: String is owned by the document (lives until
1375
+ * leptris_document_free). Do not free.
1376
+ */
1377
+ LEPTRIS_API const char* leptris_document_uri(LeptrisDocument doc);
1378
+
1379
+ /**
1380
+ * Set the document URI (#2278) — see leptris_document_uri().
1381
+ *
1382
+ * @param doc Document
1383
+ * @param uri The URI as supplied (copied); NULL or "" CLEARS it
1384
+ * @return LEPTRIS_OK, LEPTRIS_ERROR_NULL_ARG, or LEPTRIS_ERROR_MEMORY
1385
+ *
1386
+ * Memory: The string is copied; the caller keeps its own.
1387
+ */
1388
+ LEPTRIS_API LeptrisStatus leptris_document_set_uri(
1389
+ LeptrisDocument doc, const char* uri);
1390
+
1353
1391
  /**
1354
1392
  * Un-set the XML declaration (#1229): the document stops being
1355
1393
  * declaration-bearing and serialization emits none — exactly as if
@@ -3130,7 +3168,14 @@ LEPTRIS_API LeptrisNamespace leptris_element_namespace(LeptrisElement elem);
3130
3168
  * - NULL (or "") DETACHES: the resolved namespace link and the
3131
3169
  * name's prefix clear, and an xmlns="" undeclaration is added so
3132
3170
  * an in-scope default namespace cannot capture the now
3133
- * unqualified name.
3171
+ * unqualified name. The detach is PERSISTENT (#2294): an element
3172
+ * detached while no default namespace is in scope keeps that
3173
+ * intent when it is later attached under a default-namespaced
3174
+ * parent — serialization emits the xmlns="" reset there, and
3175
+ * leptris_element_namespace reports NULL. Setting a namespace
3176
+ * again (this call with a URI, add_namespace_definition with a
3177
+ * non-empty default, or leptris_element_set_namespace_uri)
3178
+ * supersedes it.
3134
3179
  * - A non-empty URI REBINDS to an IN-SCOPE declaration carrying
3135
3180
  * that URI (its prefix is adopted). A URI with no in-scope
3136
3181
  * declaration returns LEPTRIS_ERROR_NOT_FOUND — this API does
@@ -4286,8 +4331,8 @@ LEPTRIS_API const char* leptris_xinclude_get_encoding(LeptrisElement include_ele
4286
4331
  * CI's export-surface gate diffs the header against the binary. */
4287
4332
  #define LIBLEPTRIS_VERSION_MAJOR 1
4288
4333
  #define LIBLEPTRIS_VERSION_MINOR 9
4289
- #define LIBLEPTRIS_VERSION_PATCH 458
4290
- #define LIBLEPTRIS_VERSION_STRING "1.9.458"
4334
+ #define LIBLEPTRIS_VERSION_PATCH 460
4335
+ #define LIBLEPTRIS_VERSION_STRING "1.9.460"
4291
4336
 
4292
4337
  /**
4293
4338
  * Get libleptris version string
@@ -264,7 +264,7 @@ char* leptris_decode_entities_view(const struct leptris_string_view* sv, Leptris
264
264
  * @return Newly allocated string with entities decoded, or NULL on error.
265
265
  * Caller must free() the returned string.
266
266
  */
267
- char* leptris_decode_entities_with_dtd(const char* input, const LeptrisDTD* dtd) {
267
+ char* leptris_decode_entities_with_dtd(const char* input, LeptrisDTD* dtd) {
268
268
  if (!input) return NULL;
269
269
 
270
270
  /* If DTD is available, use it for full entity expansion */
@@ -288,7 +288,7 @@ char* leptris_decode_entities_with_dtd(const char* input, const LeptrisDTD* dtd)
288
288
  * If pool is non-NULL, memory is allocated from the pool.
289
289
  */
290
290
  char* leptris_decode_entities_view_with_dtd(const struct leptris_string_view* sv,
291
- const LeptrisDTD* dtd,
291
+ LeptrisDTD* dtd,
292
292
  LeptrisMemoryPool* pool) {
293
293
  if (!sv || leptris_sv_is_empty(sv)) {
294
294
  if (pool) {
@@ -61,7 +61,7 @@ char* leptris_decode_entities_view(const struct leptris_string_view* sv, Leptris
61
61
  * @return Newly allocated string with entities decoded, or NULL on error.
62
62
  * Caller must free() the returned string.
63
63
  */
64
- char* leptris_decode_entities_with_dtd(const char* input, const LeptrisDTD* dtd);
64
+ char* leptris_decode_entities_with_dtd(const char* input, LeptrisDTD* dtd);
65
65
 
66
66
  /**
67
67
  * Decode entities in a string view with DTD support.
@@ -71,9 +71,15 @@ char* leptris_decode_entities_with_dtd(const char* input, const LeptrisDTD* dtd)
71
71
  * @param pool Memory pool for allocation (can be NULL for malloc)
72
72
  * @return Newly allocated string with entities decoded, or NULL on error.
73
73
  * If pool is non-NULL, memory is allocated from the pool.
74
+ *
75
+ * leptris#2281: `dtd` is non-const — the expansion charges the DTD's
76
+ * per-parse entity-expansion budget. A NULL return with
77
+ * leptris_dtd_entity_limit_hit(dtd) true is a limit breach: the
78
+ * document parser fails the parse (leptris_dtd_entity_limit_message
79
+ * names the limit), it never falls back to the raw text.
74
80
  */
75
81
  char* leptris_decode_entities_view_with_dtd(const struct leptris_string_view* sv,
76
- const LeptrisDTD* dtd,
82
+ LeptrisDTD* dtd,
77
83
  LeptrisMemoryPool* pool);
78
84
 
79
85
  #endif /* LEPTRIS_COMMON_ENTITIES_H */