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

fix accepted ref patterns #13870

Merged
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
4 changes: 2 additions & 2 deletions conans/model/recipe_ref.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ def validate_ref(self, allow_uppercase=False):
if len(self_str) > 200:
raise ConanException(f"Package reference too long >200 {self_str}")
if not allow_uppercase:
validation_pattern = re.compile(r"^[a-z0-9_][a-z0-9_+.-]{1,100}$")
validation_pattern = re.compile(r"^[a-z0-9_][a-z0-9_+.-]{1,100}\Z")
else:
validation_pattern = re.compile(r"^[a-zA-Z0-9_][a-zA-Z0-9_+.-]{1,100}$")
validation_pattern = re.compile(r"^[a-zA-Z0-9_][a-zA-Z0-9_+.-]{1,100}\Z")
if validation_pattern.match(self.name) is None:
raise ConanException(f"Invalid package name '{self.name}'")
if validation_pattern.match(str(self.version)) is None:
Expand Down
40 changes: 40 additions & 0 deletions conans/test/integration/conanfile/set_name_version_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from parameterized import parameterized

from conans.test.assets.genconanfile import GenConanfile
from conans.test.utils.tools import TestClient, NO_SETTINGS_PACKAGE_ID
from conans.util.files import mkdir

Expand Down Expand Up @@ -150,3 +151,42 @@ def set_version(self):
client.save({"version.txt": "2.1"}, clean_first=True)
client.run("export .. ")
self.assertIn("pkg/2.1: Exported", client.out)


def test_set_version_forbidden_chars():
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", "$$$")})
c.run("export .", assert_error=True)
assert "ERROR: Invalid package version '$$$'" in c.out

conanfile = textwrap.dedent("""
from conan import ConanFile
class Lib(ConanFile):
name = "pkg"
def set_version(self):
self.version = "$$$"
""")
c.save({"conanfile.py": conanfile})
c.run("export .", assert_error=True)
assert "ERROR: Invalid package version '$$$'" in c.out


def test_set_version_carriage_return():
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", r"1.0\n")})
c.run("export .", assert_error=True)
assert "ERROR: Invalid package version '1.0" in c.out

conanfile = textwrap.dedent("""
import os
from conan import ConanFile
from conan.tools.files import load
class Lib(ConanFile):
name = "pkg"
def set_version(self):
self.version = load(self, "version.txt")
""")
c.save({"conanfile.py": conanfile,
"version.txt": "1.0\n"})
c.run("export .", assert_error=True)
assert "ERROR: Invalid package version '1.0" in c.out