diff --git a/.jules/palette.md b/.jules/palette.md
index 9a12c9d..167bbfa 100644
--- a/.jules/palette.md
+++ b/.jules/palette.md
@@ -48,3 +48,6 @@
## 2024-08-01 - 네이티브 브라우저 UI의 다크 모드 지원 강제
**학습:** CSS 미디어 쿼리(`@media (prefers-color-scheme: dark)`)를 통해 다크 모드를 지원하더라도, 브라우저의 네이티브 UI 요소(스크롤바, 기본 폼 컨트롤, 기본 백그라운드 등)는 테마 변경을 인식하지 못해 어두운 테마 환경에서 밝은 스크롤바가 표시되는 등 시각적 불일치를 초래합니다.
**조치:** 항상 HTML 문서의 `
` 영역에 ` ` 메타 태그를 명시적으로 추가하여 브라우저 수준에서 사용자의 시스템 테마(다크 모드 등)를 완전히 상속받아 일관성 있는 네이티브 UI를 렌더링하도록 보장하십시오.
+## 2026-07-15 - Provide fallback for empty directory names
+**Learning:** In Java/Kotlin, root directories return an empty string for `getName()`. This results in empty `` and `` tags, which harms accessibility. Fallbacks (e.g. `absolutePath`) must be provided for UI elements.
+**Action:** Use `name.ifEmpty { absolutePath }` when generating HTML content from File objects to ensure semantic tags are properly populated.
diff --git a/src/main/kotlin/html4tree/main.kt b/src/main/kotlin/html4tree/main.kt
index b455862..1c3c2ee 100644
--- a/src/main/kotlin/html4tree/main.kt
+++ b/src/main/kotlin/html4tree/main.kt
@@ -327,12 +327,12 @@ ${cssContent}
- ${curr_dir.getName().escapeHtml()}
+ ${curr_dir.name.ifEmpty { curr_dir.absolutePath }.escapeHtml()}
${css}
- ${curr_dir.getName().escapeHtml()}
+ ${curr_dir.name.ifEmpty { curr_dir.absolutePath }.escapeHtml()}
↰ ..
diff --git a/src/test/kotlin/html4tree/MainTest.kt b/src/test/kotlin/html4tree/MainTest.kt
index 1349471..032a8e4 100644
--- a/src/test/kotlin/html4tree/MainTest.kt
+++ b/src/test/kotlin/html4tree/MainTest.kt
@@ -95,6 +95,8 @@ class MainTest {
assertTrue(htmlContent.contains(""))
assertTrue(htmlContent.contains("이 디렉토리는 비어 있습니다."))
assertTrue(htmlContent.contains("role=\"list\""))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
}
@Test
@@ -308,6 +310,8 @@ class MainTest {
assertTrue(indexFile.exists())
val htmlContent = indexFile.readText()
assertTrue(htmlContent.contains(""))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
assertTrue(htmlContent.contains(" "))
assertTrue(htmlContent.contains(""))
assertTrue(htmlContent.contains("role=\"list\""))
@@ -401,7 +405,11 @@ class MainTest {
go(tempDir.absolutePath, -1)
- assertTrue(File(tempDir, "index.html").exists())
+ val indexFile = File(tempDir, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
val subdirIndex = File(subdir, "index.html")
assertTrue(subdirIndex.exists())
@@ -423,7 +431,12 @@ class MainTest {
go(tempDir.absolutePath, 0)
- assertTrue(File(tempDir, "index.html").exists())
+ val indexFile = File(tempDir, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+
assertFalse(File(subdir, "index.html").exists())
assertFalse(File(subsubdir, "index.html").exists())
}
@@ -438,7 +451,12 @@ class MainTest {
go(tempDir.absolutePath, -1)
- assertTrue(File(tempDir, "index.html").exists())
+ val indexFile = File(tempDir, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+
assertTrue(File(subdir, "index.html").exists())
assertFalse(File(gitDir, "index.html").exists())
}
@@ -466,7 +484,12 @@ class MainTest {
go(tempDir.absolutePath, -1)
- assertTrue(File(tempDir, "index.html").exists())
+ val indexFile = File(tempDir, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+
assertTrue(File(unreadableDir, "index.html").exists())
} finally {
unreadableDir.setReadable(true, false)
@@ -488,7 +511,12 @@ class MainTest {
val cli = Html4tree()
cli.parse(arrayOf(tempDir.absolutePath))
main(arrayOf(tempDir.absolutePath))
- assertTrue(File(tempDir, "index.html").exists())
+
+ val indexFile = File(tempDir, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
+ assertTrue(htmlContent.contains("${tempDir.name.escapeHtml()} "))
}
@Test(expected = IllegalArgumentException::class)
@@ -520,6 +548,21 @@ class MainTest {
process_dir(tempDir)
}
+ @Test
+ fun testProcessDirEmptyNameFallback() {
+ val fakeRoot = object : File(tempDir, "fakeRoot") {
+ override fun getName(): String = ""
+ }
+ fakeRoot.mkdir()
+ process_dir(fakeRoot)
+ val indexFile = File(fakeRoot, "index.html")
+ assertTrue(indexFile.exists())
+ val htmlContent = indexFile.readText()
+ val expectedFallback = fakeRoot.absolutePath.escapeHtml()
+ assertTrue(htmlContent.contains("$expectedFallback "))
+ assertTrue(htmlContent.contains("$expectedFallback "))
+ }
+
@Test(expected = IllegalArgumentException::class)
fun testGoBlankDir() {
go(" ", -1)