fix: prevent romaji conversion stack overflow on long task names
This commit is contained in:
parent
67f6fc685c
commit
291e05a24d
@ -239,17 +239,27 @@ describe('summarizeTaskName', () => {
|
|||||||
expect(result.length).toBeLessThanOrEqual(30);
|
expect(result.length).toBeLessThanOrEqual(30);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle mixed Japanese/English with romanization', async () => {
|
it('should handle mixed Japanese/English with romanization', async () => {
|
||||||
// When
|
// When
|
||||||
const result = await summarizeTaskName('Add romanization', { cwd: '/project', useLLM: false });
|
const result = await summarizeTaskName('Add romanization', { cwd: '/project', useLLM: false });
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(result).toMatch(/^[a-z0-9-]+$/);
|
expect(result).toMatch(/^[a-z0-9-]+$/);
|
||||||
expect(result).not.toMatch(/^-|-$/); // No leading/trailing hyphens
|
expect(result).not.toMatch(/^-|-$/); // No leading/trailing hyphens
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use romaji by default', async () => {
|
it('should handle very long names in romanization mode without stack overflow', async () => {
|
||||||
// Given: branchNameStrategy is not set (undefined)
|
const result = await summarizeTaskName('a'.repeat(12000), {
|
||||||
|
cwd: '/project',
|
||||||
|
useLLM: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toBe('a'.repeat(30));
|
||||||
|
expect(mockProviderCall).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should use romaji by default', async () => {
|
||||||
|
// Given: branchNameStrategy is not set (undefined)
|
||||||
mockResolveConfigValues.mockReturnValue({
|
mockResolveConfigValues.mockReturnValue({
|
||||||
provider: 'claude',
|
provider: 'claude',
|
||||||
model: undefined,
|
model: undefined,
|
||||||
|
|||||||
@ -14,12 +14,33 @@ import type { SummarizeOptions } from './types.js';
|
|||||||
export type { SummarizeOptions };
|
export type { SummarizeOptions };
|
||||||
|
|
||||||
const log = createLogger('summarize');
|
const log = createLogger('summarize');
|
||||||
|
const MAX_ROMAJI_CHUNK_SIZE = 1024;
|
||||||
|
|
||||||
|
function toRomajiSafely(text: string): string {
|
||||||
|
const romajiOptions = { customRomajiMapping: {} };
|
||||||
|
try {
|
||||||
|
if (text.length <= MAX_ROMAJI_CHUNK_SIZE) {
|
||||||
|
return wanakana.toRomaji(text, romajiOptions);
|
||||||
|
}
|
||||||
|
const convertedChunks: string[] = [];
|
||||||
|
for (let i = 0; i < text.length; i += MAX_ROMAJI_CHUNK_SIZE) {
|
||||||
|
convertedChunks.push(
|
||||||
|
wanakana.toRomaji(text.slice(i, i + MAX_ROMAJI_CHUNK_SIZE), romajiOptions),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return convertedChunks.join('');
|
||||||
|
} catch {
|
||||||
|
// Avoid blocking branch/task creation on rare parser edge cases or deep recursion
|
||||||
|
// with very long mixed/ASCII inputs.
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert Japanese text to romaji slug.
|
* Convert Japanese text to romaji slug.
|
||||||
*/
|
*/
|
||||||
function toRomajiSlug(text: string): string {
|
function toRomajiSlug(text: string): string {
|
||||||
const romaji = wanakana.toRomaji(text, { customRomajiMapping: {} });
|
const romaji = toRomajiSafely(text);
|
||||||
return slugify(romaji);
|
return slugify(romaji);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user