diff --git a/changelog.d/8438.issue b/changelog.d/8438.issue new file mode 100644 index 000000000..b67fff1ab --- /dev/null +++ b/changelog.d/8438.issue @@ -0,0 +1 @@ +Preserve form action URLs and configured attributes with context-specific encoding diff --git a/lib/html_form.php b/lib/html_form.php index 30b35c490..69b633748 100644 --- a/lib/html_form.php +++ b/lib/html_form.php @@ -47,7 +47,7 @@ function draw_edit_form(array $array) : void { if (cacti_sizeof($fields_array)) { if (!isset($config_array['no_form_tag'])) { - print "
'; + $html = ob_get_contents(); + } finally { + ob_end_clean(); + } + + $document = new DOMDocument(); + $previous = libxml_use_internal_errors(true); + + try { + expect($document->loadHTML('' . $html))->toBeTrue(); + } finally { + libxml_clear_errors(); + libxml_use_internal_errors($previous); + } + + $forms = $document->getElementsByTagName('form'); + expect($forms->length)->toBe(1) + ->and($forms->item(0)->getAttribute('action'))->toBe($action) + ->and($forms->item(0)->getAttribute('method'))->toBe('post') + ->and($document->getElementsByTagName('input')->item(0)->getAttribute('value'))->toBe('7') + ->and($document->getElementsByTagName('script')->length)->toBe(0); +})->with('form action URLs'); + +it('preserves generated form IDs and the non-AJAX form mode', function () { + $ids = []; + + for ($i = 0; $i < 2; $i++) { + ob_start(); + + try { + form_start('edit.php'); + $ids[] = $GLOBALS['form_id']; + form_end(false); + $html = ob_get_contents(); + } finally { + ob_end_clean(); + } + + expect($html)->not->toContain('