Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changes-entries/70378.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_macro: Fix empty or garbled "In file:" labels shown by mod_info
for directives expanded from a macro. PR 70378.
[Leo Bicknell <bicknell@ufp.org>]
3 changes: 2 additions & 1 deletion modules/core/mod_macro.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,8 @@ static const char *use_macro(cmd_parms * cmd, void *dummy, const char *arg)
replacements->nelts, macro->arguments->nelts);
}

where = apr_psprintf(cmd->temp_pool,
/* Directives built from the macro keep this as their filename */
where = apr_psprintf(cmd->pool,
"macro '%s' (%s) used on line %d of \"%s\"",
macro->name, macro->location,
cmd->config_file->line_number,
Expand Down
2 changes: 1 addition & 1 deletion test/modules/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CoreTestSetup(HttpdTestSetup):
def __init__(self, env: 'HttpdTestEnv'):
super().__init__(env=env)
self.add_source_dir(os.path.dirname(inspect.getfile(CoreTestSetup)))
self.add_modules(["cgid","include","userdir","headers"])
self.add_modules(["cgid","include","userdir","headers","macro","info"])


class CoreTestEnv(HttpdTestEnv):
Expand Down
50 changes: 50 additions & 0 deletions test/modules/core/test_018_macro_info_filename.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""mod_info must show the right "In file:" label for directives expanded
from a mod_macro <Macro>.

use_macro() built the "macro 'X' (...) used on line N of ..." label in the
temporary configuration pool, and ap_build_config_sub() keeps only a pointer
to it as the directive's filename. The temporary pool is destroyed once the
configuration is read, so /server-info?config printed empty or garbled
labels for some of those directives. PR 70378.
"""

import re

import pytest

from pyhttpd.conf import HttpdConf


class TestMacroInfoFilename:

USES = 300

@pytest.fixture(autouse=True, scope='class')
@classmethod
def _class_scope(cls, env):
conf = HttpdConf(env)
conf.add([
"<Location /server-info>",
" SetHandler server-info",
" Require local",
"</Location>",
"<Macro TestMacroInfo>",
" Header set X-Macro-Info v",
"</Macro>",
])
conf.add(["Use TestMacroInfo"] * cls.USES)
conf.install()
assert env.apache_restart() == 0

def test_core_018_01_macro_labels_intact(self, env):
url = f"http://127.0.0.1:{env.http_port}/server-info?config"
r = env.curl_get(url)
assert r.response["status"] == 200, f"{r}"
body = r.response["body"].decode("latin-1")
labels = re.findall(r"In file: (.*?)</strong>", body)
# mod_macro lower-cases the name; mod_info escapes the quotes
good = re.compile(r"^macro 'testmacroinfo' \(defined on line \d+ of "
r"&quot;.+&quot;\) used on line \d+ of &quot;.+&quot;$")
used = [lab for lab in labels if good.match(lab)]
assert len(used) == self.USES, \
f"{self.USES - len(used)} macro labels missing or garbled: {labels[:3]}"
Loading