Skip to content
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
2 changes: 1 addition & 1 deletion b2/_internal/_utils/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from b2sdk.v3.exception import B2Error

_B2ID_PATTERN = re.compile(r'^b2id://(?P<file_id>[a-zA-Z0-9:_-]+)$', re.IGNORECASE)
_B2_PATTERN = re.compile(r'^b2://(?P<bucket>[a-z0-9-]*)(?P<path>/.*)?$', re.IGNORECASE)
_B2_PATTERN = re.compile(r'^b2://(?P<bucket>[a-z0-9.-]*)(?P<path>/.*)?$', re.IGNORECASE)
_SCHEME_PATTERN = re.compile(r'(?P<scheme>[a-z0-9]*)://.*', re.IGNORECASE)
_CONTROL_CHARACTERS_AND_SPACE = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f '

Expand Down
1 change: 1 addition & 0 deletions changelog.d/+b2-uri-bucket-period.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `b2://` URI parsing to accept bucket names containing periods.
17 changes: 17 additions & 0 deletions test/integration/test_b2_command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,23 @@ def test_download(b2_tool, persistent_bucket, sample_filepath, uploaded_sample_f
assert output_b.read_text() == sample_filepath.read_text()


def test_download__period_in_bucket_name(b2_tool, schedule_bucket_cleanup, sample_filepath, tmp_path):
bucket_name = b2_tool.generate_bucket_name()
bucket_name = bucket_name[:-2] + ".x"
schedule_bucket_cleanup(bucket_name)
b2_tool.should_succeed(
['bucket', 'create', bucket_name, 'allPrivate', *b2_tool.get_bucket_info_args()]
)
b2_tool.should_succeed_json(
['file', 'upload', '--quiet', bucket_name, str(sample_filepath), 'kitten.jpg']
)
output = tmp_path / 'kitten.jpg'
b2_tool.should_succeed(
['file', 'download', '--quiet', f'b2://{bucket_name}/kitten.jpg', str(output)]
)
assert output.read_text() == sample_filepath.read_text()


def test_basic(b2_tool, persistent_bucket, sample_file, tmp_path, b2_uri_args, apiver_int):
bucket_name = persistent_bucket.bucket_name
subfolder = f'{persistent_bucket.subfolder}/'
Expand Down
2 changes: 2 additions & 0 deletions test/unit/_utils/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def test_b2fileuri_str():
('./some/local/path', Path('some/local/path')),
('.', Path('')),
('b2://bucket', B2URI(bucket_name='bucket')),
('b2://one.two/kitten.jpg', B2URI(bucket_name='one.two', path='kitten.jpg')),
('b2://one.two', B2URI(bucket_name='one.two')),
(' b2://bucket', B2URI(bucket_name='bucket')),
('b2://bucket/', B2URI(bucket_name='bucket')),
('b2://bucket/path/to/dir/', B2URI(bucket_name='bucket', path='path/to/dir/')),
Expand Down
Loading