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

warn if special chars in exported refs #12053

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
13 changes: 12 additions & 1 deletion conans/model/recipe_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import re
from functools import total_ordering

from conan.api.output import ConanOutput
from conans.errors import ConanException
from conans.model.version import Version
from conans.util.dates import timestamp_to_str
Expand Down Expand Up @@ -124,7 +125,7 @@ def validate_ref(self):
if self_str != self_str.lower():
raise ConanException(f"Conan packages names '{self_str}' must be all lowercase")
if len(self_str) > 200:
raise ConanException(f"Package reference too long >250 {self_str}")
raise ConanException(f"Package reference too long >200 {self_str}")
validation_pattern = re.compile(r"^[a-z0-9_][a-z0-9_+.-]{1,100}$")
if validation_pattern.match(self.name) is None:
raise ConanException(f"Invalid package name '{self.name}'")
Expand All @@ -135,6 +136,16 @@ def validate_ref(self):
if self.channel and validation_pattern.match(self.channel) is None:
raise ConanException(f"Invalid package channel '{self.channel}'")

# Warn if they use .+- in the name/user/channel, as it can be problematic for generators
pattern = re.compile(r'[.+-]')
if pattern.search(self.name):
ConanOutput().warning(f"Name containing special chars is discouraged '{self.name}'")
if self.user and pattern.search(self.user):
ConanOutput().warning(f"User containing special chars is discouraged '{self.user}'")
if self.channel and pattern.search(self.channel):
ConanOutput().warning(f"Channel containing special chars is discouraged "
f"'{self.channel}'")
franramirez688 marked this conversation as resolved.
Show resolved Hide resolved

def matches(self, pattern, is_consumer):
negate = False
if pattern.startswith("!"):
Expand Down
11 changes: 11 additions & 0 deletions conans/test/integration/command/export/export_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,17 @@ def test_export_invalid_refs():
assert "ERROR: Invalid package channel 'channel%'" in c.out


def test_warn_special_chars_refs():
c = TestClient()
c.save({"conanfile.py": GenConanfile()})
c.run("export . --name=pkg.name --version=0.1")
assert "WARN: Name containing special chars is discouraged 'pkg.name'" in c.out
c.run("export . --name=name --version=0.1 --user=user+some")
assert "WARN: User containing special chars is discouraged 'user+some'" in c.out
c.run("export . --name=pkg.name --version=0.1 --user=user --channel=channel-some")
assert "WARN: Channel containing special chars is discouraged 'channel-some'" in c.out


def test_export_json():
c = TestClient()
c.save({"conanfile.py": GenConanfile()})
Expand Down