diff --git a/docs/changelog.md b/docs/changelog.md index 9ebebcce..52275d06 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,7 @@ ## Unreleased +- **Fix:** PDF Generator font data (Cyrillic and Arabic) is now attached to the Super Forms common script, so it still loads when a JavaScript optimization plugin reorders or delays scripts. - **Fix:** PDF Generator "Enable debug mode" now only downloads the PDF and no longer submits the form, so no entry is saved and no e-mails are sent. - **Fix:** When the PDF cannot be created, a message is shown and the visitor can close it and try again, instead of the form staying on "Generating PDF file..." forever. Nothing is submitted in that case. diff --git a/includes/class-shortcodes.php b/includes/class-shortcodes.php index fb934032..a8da897c 100644 --- a/includes/class-shortcodes.php +++ b/includes/class-shortcodes.php @@ -6524,27 +6524,11 @@ public static function super_form_func( $atts, $elements_only=false ) { if($settings['_pdf']['textRendering']==='true'){ // Cyrillic compatible font if($settings['_pdf']['cyrillicText']==='true') { - add_action( 'wp_footer', function(){ - ?> - - - - ' . $js . ''; + }, 100 ); + } + } endif; diff --git a/tests/test-security-pdf-font-inline-script.php b/tests/test-security-pdf-font-inline-script.php new file mode 100644 index 00000000..4e38d76a --- /dev/null +++ b/tests/test-security-pdf-font-inline-script.php @@ -0,0 +1,72 @@ +create_form( 'publish', array(), array( '_pdf' => $pdf ) ); + SUPER_Shortcodes::super_form_func( array( 'id' => (string) $form ) ); + } + + public function test_fonts_attach_to_super_common_after_block() { + $this->render_pdf_form(); + + $after = wp_scripts()->get_data( 'super-common', 'after' ); + $this->assertIsArray( $after ); + $this->assertStringContainsString( 'super_common_i18n.fonts', implode( "\n", $after ) ); + } + + public function test_fonts_print_after_localized_var() { + $this->render_pdf_form(); + + ob_start(); + wp_print_scripts( array( 'super-common' ) ); + $out = ob_get_clean(); + + $var_pos = strpos( $out, 'var super_common_i18n' ); + $fonts_pos = strpos( $out, 'super_common_i18n.fonts' ); + $after_pos = strpos( $out, 'id="super-common-js-after"' ); + $this->assertNotFalse( $var_pos ); + $this->assertNotFalse( $fonts_pos ); + $this->assertNotFalse( $after_pos ); + $this->assertLessThan( $fonts_pos, $var_pos ); + $this->assertLessThan( $fonts_pos, $after_pos ); + } + + public function test_fonts_fall_back_to_footer_when_super_common_already_printed() { + wp_scripts()->done[] = 'super-common'; + $this->render_pdf_form(); + + remove_action( 'wp_footer', 'the_block_template_skip_link' ); + ob_start(); + do_action( 'wp_footer' ); + $out = ob_get_clean(); + + $this->assertStringContainsString( 'super_common_i18n.fonts', $out ); + } +}