diff options
context:
space:
mode:
Diffstat (limited to 'source/filter.c')
-rw-r--r--source/filter.c10
1 file changed, 10 insertions, 0 deletions
diff --git a/source/filter.c b/source/filter.c
index e15a5e9..f195534 100644
--- a/source/filter.c
+++ b/source/filter.c
@@ -216,6 +216,10 @@ static inline int hook_lua_filter(lua_State *lua_state, void (*fn)(const char *t
save_filter = current_write_filter;
unhook_write();
fn(str);
+ // fn buffers, so empty it while the hook is still off. Re-hooking first
+ // would send the page's own bytes back into the filter that asked for
+ // them to be written.
+ html_flush();
hook_write(save_filter, save_filter_write);
return 0;
@@ -368,6 +372,9 @@ int cgit_open_filter(struct cgit_filter *filter, ...)
va_list ap;
if (!filter)
return 0;
+ // Whatever is still buffered belongs to the page, not to the filter
+ // that is about to take over stdout.
+ html_flush();
va_start(ap, filter);
result = filter->open(filter, ap);
va_end(ap);
@@ -378,6 +385,9 @@ int cgit_close_filter(struct cgit_filter *filter)
{
if (!filter)
return 0;
+ // Anything written while the filter was open is meant for it, so this
+ // has to go out before the filter hands stdout back.
+ html_flush();
return filter->close(filter);
}