Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public class MapKitViewHost: NSObject, @preconcurrency MapKitHostApi {
#endif

func addTileOverlay(overlay overlayData: PlatformTileOverlay) throws {
guard overlayData.urlTemplate.hasPrefix("https://") || overlayData.urlTemplate.hasPrefix("http://") else {
throw mapKitError("invalid-url-template", "Tile overlay urlTemplate must use https:// or http:// scheme.")
}
let overlay = FlutterTileOverlay(fromPlatform: overlayData)
if !overlay.id.isEmpty, tileOverlays[overlay.id] != nil {
try removeTileOverlay(tileOverlayId: overlay.id)
Expand Down
26 changes: 16 additions & 10 deletions lib/src/mk_tile_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,22 @@ final class MKTileOverlay {
/// Creates a new Platform object.
///
/// See: https://developer.apple.com/documentation/mapkit
PlatformTileOverlay toPlatform() => PlatformTileOverlay(
id: id.value,
urlTemplate: urlTemplate,
minimumZ: minimumZ,
maximumZ: maximumZ,
tileSize: tileSize,
canReplaceMapContent: canReplaceMapContent,
alpha: alpha,
level: level,
);
PlatformTileOverlay toPlatform() {
if (!urlTemplate.startsWith('https://') &&
!urlTemplate.startsWith('http://')) {
throw ArgumentError('urlTemplate must use https:// or http:// scheme');
}
return PlatformTileOverlay(
id: id.value,
urlTemplate: urlTemplate,
minimumZ: minimumZ,
maximumZ: maximumZ,
tileSize: tileSize,
canReplaceMapContent: canReplaceMapContent,
alpha: alpha,
level: level,
);
}

@override
bool operator ==(Object other) =>
Expand Down
8 changes: 8 additions & 0 deletions test/mk_tile_overlay_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ void main() {
),
).throws<AssertionError>();
});

test('rejects invalid url template scheme in toPlatform()', () {
const overlay = MKTileOverlay(
id: MKTileOverlayId('bad_scheme'),
urlTemplate: 'file:///etc/passwd',
);
check(() => overlay.toPlatform()).throws<ArgumentError>();
});
});

group('equality', () {
Expand Down
Loading