Skip to content
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
1 change: 1 addition & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Weblate 2026.12
* Removed internal filesystem paths and raw command output from gettext and script :ref:`add-on alerts <alerts>`.
* Redacted remote source URLs from :ref:`JavaScript localization CDN <addon-weblate.cdn.cdnjs>` alerts and activity logs, including existing records.
* Applied the destination project’s :ref:`access controls <access-control>` to component history after a move, and linked new category rename and move events to their category.
* Validated App Store metadata destinations before saving or deleting translation files through symlinked directories.

* Required project management permission to change a component URL through the API and prevented :ref:`case-insensitive slug conflicts <component-slug>` from blocking repository cleanup.
* Required the site-wide ``language.add`` permission to :http:post:`create a language through the REST API </api/languages/>`.
Expand Down
64 changes: 63 additions & 1 deletion weblate/formats/tests/test_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,81 @@

import os.path
from pathlib import Path
from tempfile import TemporaryDirectory
from typing import IO
from unittest.mock import Mock, patch

from django.core.exceptions import ValidationError
from django.test import SimpleTestCase

from weblate.formats.tests.test_formats import BaseFormatTest
from weblate.formats.txt import AppStoreFormat, MultiparserError
from weblate.formats.txt import AppStoreFormat, MultiparserError, TextItem
from weblate.lang.models import Language
from weblate.trans.tests.utils import get_test_file

APPSTORE_FILE = get_test_file("short_description.txt")


class AppStoreWritePathTest(SimpleTestCase):
def test_save_rejects_symlinked_destination_directory(self) -> None:
with TemporaryDirectory() as directory:
root = Path(directory)
base = root / "metadata"
outside = root / "outside"
base.mkdir()
outside.mkdir()
(base / "changelogs").symlink_to(outside, target_is_directory=True)

def validate(filename: str) -> str:
if not Path(filename).resolve().is_relative_to(base.resolve()):
msg = "Invalid symbolic link in a repository."
raise ValidationError(msg)
return filename

store = AppStoreFormat(str(base), file_validator=validate)
unit = TextItem("changelogs/title.txt", 1, "attacker")
unit.needs_save = True
store.store.units.append(unit)

with self.assertRaises(ValidationError):
store.save()
target = outside / "title.txt"
self.assertFalse(target.exists())

target.write_text("keep", encoding="utf-8")
with self.assertRaises(ValidationError):
store.save()
self.assertEqual(target.read_text(encoding="utf-8"), "keep")

def test_delete_rejects_symlinked_destination_directory(self) -> None:
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
with TemporaryDirectory() as directory:
root = Path(directory)
base = root / "metadata"
outside = root / "outside"
base.mkdir()
outside.mkdir()

def validate(filename: str) -> str:
if not Path(filename).resolve().is_relative_to(base.resolve()):
msg = "Invalid symbolic link in a repository."
raise ValidationError(msg)
return filename

store = AppStoreFormat(str(base), file_validator=validate)
(base / "changelogs").symlink_to(outside, target_is_directory=True)
target = outside / "title.txt"
unit = TextItem("changelogs/title.txt", 1, "")
for exists in (True, False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2: This change drops the save() check that an existing target file keeps its contents. Only delete_unit now runs with an existing file, and save() is only tested when the file is absent. Keep the existing-file save case, for example by running save() under the same exists loop.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At weblate/formats/tests/test_txt.py, line 69:

<comment>This change drops the save() check that an existing target file keeps its contents. Only delete_unit now runs with an existing file, and save() is only tested when the file is absent. Keep the existing-file save case, for example by running save() under the same `exists` loop.</comment>

<file context>
@@ -65,14 +65,16 @@ class AppStoreWritePathTest(SimpleTestCase):
-            with self.assertRaises(ValidationError):
-                store.save()
-            self.assertEqual(target.read_text(encoding="utf-8"), "keep")
+            for exists in (True, False):
+                with self.subTest(exists=exists):
+                    if exists:
</file context>

with self.subTest(exists=exists):
if exists:
target.write_text("keep", encoding="utf-8")
with self.assertRaises(ValidationError):
store.delete_unit(unit)
if exists:
self.assertEqual(target.read_text(encoding="utf-8"), "keep")
target.unlink()


class AppStoreFormatTest(BaseFormatTest):
format_class = AppStoreFormat
FILE = APPSTORE_FILE
Expand Down
2 changes: 1 addition & 1 deletion weblate/formats/txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def load_parser(self):
return result

def get_filename(self, name):
return os.path.join(self.base, name)
return self.file_validator(os.path.join(self.base, name))


class AppStoreParser(MultiParser):
Expand Down
Loading