Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(load_config): enforce stricter extension checks #5591

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 1 addition & 2 deletions lib/hexo/load_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,12 @@ export = async (ctx: Hexo): Promise<void> => {
}
ctx.theme_script_dir = join(ctx.theme_dir, 'scripts') + sep;
ctx.theme = new Theme(ctx, { ignored });

};

async function findConfigPath(path: string): Promise<string> {
const { dir, name } = parse(path);

const files = await readdir(dir);
const item = files.find(item => item.startsWith(name));
const item = files.find(item => item === name + '.json');
Copy link
Member

@SukkaW SukkaW Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make sense. That should be using path.basename(item) === 'config'.

if (item != null) return join(dir, item);
}
3 changes: 3 additions & 0 deletions test/scripts/hexo/load_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ describe('Load config', () => {
after(() => rmdir(hexo.base_dir));

beforeEach(() => {
hexo.config_path = join(hexo.base_dir, '_config.yml');
hexo.config = JSON.parse(JSON.stringify(defaultConfig));
});

Expand Down Expand Up @@ -41,6 +42,7 @@ describe('Load config', () => {
await writeFile(configPath, '{"baz": 3}');
await loadConfig(hexo);
hexo.config.baz.should.eql(3);
hexo.config_path.should.eql(configPath);
} finally {
await unlink(configPath);
}
Expand All @@ -53,6 +55,7 @@ describe('Load config', () => {
await writeFile(configPath, 'foo: 1');
await loadConfig(hexo);
hexo.config.should.eql(defaultConfig);
hexo.config_path.should.not.eql(configPath);
} finally {
await unlink(configPath);
}
Expand Down
Loading