Show More
@@ -112,14 +112,13 b' class SimpleVCS(object):' | |||
|
112 | 112 | vcs_repo_name and is_shadow_repo on the current instance. |
|
113 | 113 | """ |
|
114 | 114 | # TODO: martinb: Move to class or module scope. |
|
115 | # TODO: martinb: Check if we have to use re.UNICODE. | |
|
116 | # TODO: martinb: Check which chars are allowed for repo/group names. | |
|
117 | # These chars are excluded: '`?=[]\;\'"<>,/~!@#$%^&*()+{}|: ' | |
|
118 | # Code from: rhodecode/lib/utils.py:repo_name_slug() | |
|
115 | from rhodecode.lib.utils import SLUG_RE | |
|
119 | 116 | pr_regex = re.compile( |
|
120 |
'(?P< |
|
|
121 |
' |
|
|
122 |
'/pull-request/(?P<pr_id>\d+) |
|
|
117 | '(?P<groups>(?:{slug_pat})(?:/{slug_pat})*)' # repo groups | |
|
118 | '/(?P<target>{slug_pat})' # target repo | |
|
119 | '/pull-request/(?P<pr_id>\d+)' # pull request | |
|
120 | '/repository$' # shadow repo | |
|
121 | .format(slug_pat=SLUG_RE.pattern)) | |
|
123 | 122 | |
|
124 | 123 | # Get url repo name from environment. |
|
125 | 124 | self.url_repo_name = self._get_repository_name(environ) |
@@ -58,26 +58,16 b' log = logging.getLogger(__name__)' | |||
|
58 | 58 | |
|
59 | 59 | REMOVED_REPO_PAT = re.compile(r'rm__\d{8}_\d{6}_\d{6}__.*') |
|
60 | 60 | |
|
61 | _license_cache = None | |
|
62 | ||
|
63 | ||
|
64 | def recursive_replace(str_, replace=' '): | |
|
65 | """ | |
|
66 | Recursive replace of given sign to just one instance | |
|
67 | ||
|
68 | :param str_: given string | |
|
69 | :param replace: char to find and replace multiple instances | |
|
61 | # String of characters which are not allowed in repo/group slugs. | |
|
62 | SLUG_BAD_CHARS = re.escape('`?=[]\;\'"<>,/~!@#$%^&*()+{}|:') | |
|
63 | # Regex that matches forbidden characters in repo/group slugs. | |
|
64 | SLUG_BAD_CHAR_RE = re.compile('[{}]'.format(SLUG_BAD_CHARS)) | |
|
65 | # Regex that matches allowed characters in repo/group slugs. | |
|
66 | SLUG_GOOD_CHAR_RE = re.compile('[^{}]'.format(SLUG_BAD_CHARS)) | |
|
67 | # Regex that matches whole repo/group slugs. | |
|
68 | SLUG_RE = re.compile('[^{}]+'.format(SLUG_BAD_CHARS)) | |
|
70 | 69 | |
|
71 | Examples:: | |
|
72 | >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') | |
|
73 | 'Mighty-Mighty-Bo-sstones' | |
|
74 | """ | |
|
75 | ||
|
76 | if str_.find(replace * 2) == -1: | |
|
77 | return str_ | |
|
78 | else: | |
|
79 | str_ = str_.replace(replace * 2, replace) | |
|
80 | return recursive_replace(str_, replace) | |
|
70 | _license_cache = None | |
|
81 | 71 | |
|
82 | 72 | |
|
83 | 73 | def repo_name_slug(value): |
@@ -86,14 +76,11 b' def repo_name_slug(value):' | |||
|
86 | 76 | This function is called on each creation/modification |
|
87 | 77 | of repository to prevent bad names in repo |
|
88 | 78 | """ |
|
79 | replacement_char = '-' | |
|
89 | 80 | |
|
90 | 81 | slug = remove_formatting(value) |
|
91 | slug = strip_tags(slug) | |
|
92 | ||
|
93 | for c in """`?=[]\;'"<>,/~!@#$%^&*()+{}|: """: | |
|
94 | slug = slug.replace(c, '-') | |
|
95 | slug = recursive_replace(slug, '-') | |
|
96 | slug = collapse(slug, '-') | |
|
82 | slug = SLUG_BAD_CHAR_RE.sub(replacement_char, slug) | |
|
83 | slug = collapse(slug, replacement_char) | |
|
97 | 84 | return slug |
|
98 | 85 | |
|
99 | 86 |
General Comments 0
You need to be logged in to leave comments.
Login now