diff options
author | root <root@rbsd.ankarstrom.se> | 2021-04-26 19:33:46 +0000 |
---|---|---|
committer | root <root@rbsd.ankarstrom.se> | 2021-04-26 19:33:46 +0000 |
commit | dd107ea3d822f14f08198135ae2fc5b3b1d454b6 (patch) | |
tree | c72f7e27c099aee3670ab4afcd53a9f4dc25c2ca /lib | |
parent | e1c7d5442ca1d3bd67c200d2dbd94bd0e40e72bd (diff) | |
download | Apache-Inject-dd107ea3d822f14f08198135ae2fc5b3b1d454b6.tar.gz |
Fix regex bug, support HTML comments
I added \s* after <body> to match any potential newline (and, for
good measure, whitespace) after <body>. One would usually rather
have this:
<body>
My header
than this:
<body>My header
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Apache/Inject.pm | 18 | ||||
-rw-r--r-- | lib/Apache/Inject/Handler.pm | 11 |
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/Apache/Inject.pm b/lib/Apache/Inject.pm index 09bf18a..89c0db8 100644 --- a/lib/Apache/Inject.pm +++ b/lib/Apache/Inject.pm @@ -180,6 +180,18 @@ file, as well as the contents of the C<InjectHeader> and C<InjectFooter> files, concatenates them intelligently and prints their combined contents. +=head1 CAVEATS + +Apache::Inject::Handler uses regular expressions to determine the +proper location of the injected header. It supports all valid HTML. +However, it does not take into account that embedded CSS and +JavaScript code can contain strings that look like valid opening +and closing HTML tags. + +On FreeBSD, you may need to enable the accf_http kernel module in +order for the tests to work. Note that Apache::Inject works fine +without the module; it is only the tests that require it. + =head1 DIAGNOSTICS Apache::Inject and Apache::Inject::Handler log all errors and @@ -220,12 +232,6 @@ cannot retrieve the current document root from Apache. =back -=head1 CAVEATS - -On FreeBSD, you may need to enable the accf_http kernel module in -order for the tests to work. Note that Apache::Inject works fine -without the module; it is only the tests that require it. - =head1 AUTHOR John Ankarström, E<lt>john [at] ankarstrom.seE<gt> diff --git a/lib/Apache/Inject/Handler.pm b/lib/Apache/Inject/Handler.pm index 0e054e7..ae81fbb 100644 --- a/lib/Apache/Inject/Handler.pm +++ b/lib/Apache/Inject/Handler.pm @@ -12,8 +12,11 @@ use Apache2::RequestUtil (); my $doc = qr{ \A (?<head> \s* + ( <!-- .*? --> )? \s* ( <!doctype[^>]*> )? \s* + ( <!-- .*? --> )? \s* ( <html[^>]*> )? \s* + ( <!-- .*? --> )? \s* ( <head[^>]*> .*? </head> \s* | ( <meta[^>]*> \s* | <link[^>]*> \s* @@ -21,12 +24,16 @@ my $doc = qr{ | <style[^>]*> .*? </style> \s* | <script[^>]*> .*? </script> \s* | <base[^>]*> \s* + | <!-- .*? --> \s* )+ )? - (<body[^>]*>)? + ( <!-- .*? --> )? \s* + ( <body[^>]*> )? \s* )? (?<body> .*? ) - (?<rest> </html> \s* )? + (?<rest> </html> \s* + ( <!-- .*? --> )? \s* + )? \z }xmsi; |