Skip to content

Commit

Permalink
Merge pull request #2562 from nextcloud/fix/nextcloud/webdav-subpath
Browse files Browse the repository at this point in the history
  • Loading branch information
provokateurin authored Oct 19, 2024
2 parents 91a712e + d68f74a commit 4919ea5
Show file tree
Hide file tree
Showing 3 changed files with 271 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ abstract class Credentials implements Built<Credentials, CredentialsBuilder> {
/// A human readable representation of [username] and [serverURL].
@memoized
String get humanReadableID {
// Maybe also show path if it is not '/' ?
final buffer = StringBuffer()
..write(username)
..write('@')
Expand All @@ -55,6 +54,9 @@ abstract class Credentials implements Built<Credentials, CredentialsBuilder> {
..write(':')
..write(serverURL.port);
}
if (serverURL.path.isNotEmpty) {
buffer.write(serverURL.path);
}

return buffer.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class WebDavFile {
return PathUri(
isAbsolute: false,
isDirectory: href.isDirectory,
pathSegments: href.pathSegments.sublist(webdavBase.pathSegments.length),
// The server might be hosted at a subpath, so we don't have a fixed number of path segments to remove
pathSegments: href.pathSegments.sublist(href.pathSegments.indexOf('remote.php') + 2),
);
}();

Expand Down
266 changes: 266 additions & 0 deletions packages/nextcloud/test/api/webdav/models/webdav_file_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
import 'package:nextcloud/src/api/webdav/models/models.dart';
import 'package:test/expect.dart';
import 'package:test/scaffolding.dart';

void main() {
test('props', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: null,
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 404 Not Found',
prop: WebDavProp(ocSize: 1),
),
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(ocSize: 2),
),
],
),
).props.ocSize,
2,
);
});

group('path', () {
group('Root', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def.txt',
propstats: [],
),
).path,
PathUri.parse('abc/def.txt'),
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def/',
propstats: [],
),
).path,
PathUri.parse('abc/def/'),
);
});
});

group('Subpath', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/subpath/remote.php/webdav/abc/def.txt',
propstats: [],
),
).path,
PathUri.parse('abc/def.txt'),
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/subpath/remote.php/webdav/abc/def/',
propstats: [],
),
).path,
PathUri.parse('abc/def/'),
);
});
});
});

group('name', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def.txt',
propstats: [],
),
).name,
'def.txt',
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def/',
propstats: [],
),
).name,
'def',
);
});
});

group('isHidden', () {
group('From prop', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def.txt',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(
ncHidden: true,
),
),
],
),
).isHidden,
true,
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def/',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(
ncHidden: true,
),
),
],
),
).isHidden,
true,
);
});
});

group('From path', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/.def.txt',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(),
),
],
),
).isHidden,
true,
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/.def/',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(),
),
],
),
).isHidden,
true,
);
});
});
});

group('isDirectory', () {
group('From prop', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def.txt',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(
davResourcetype: WebDavResourcetype(
collection: null,
),
),
),
],
),
).isDirectory,
false,
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def/',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(
davResourcetype: WebDavResourcetype(
collection: [],
),
),
),
],
),
).isDirectory,
true,
);
});
});

group('From path', () {
test('File', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def.txt',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(),
),
],
),
).isDirectory,
false,
);
});

test('Directory', () {
expect(
WebDavFile(
response: const WebDavResponse(
href: '/remote.php/webdav/abc/def/',
propstats: [
WebDavPropstat(
status: 'HTTP/1.1 200 OK',
prop: WebDavProp(),
),
],
),
).isDirectory,
true,
);
});
});
});
}

0 comments on commit 4919ea5

Please sign in to comment.