Merge pull request #6376 from vector-im/fix/mna/geo-uri-pattern

[Location Share] - Adding missing prefix "u=" for uncertainty in geo URI (PSF-945)
This commit is contained in:
Maxime NATUREL 2022-06-28 09:24:55 +02:00 committed by GitHub
commit af3718d202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 31 additions and 23 deletions

1
changelog.d/6375.bugfix Normal file
View File

@ -0,0 +1 @@
[Location Share] - Adding missing prefix "u=" for uncertainty in geo URI

View File

@ -22,7 +22,7 @@ import com.squareup.moshi.JsonClass
@JsonClass(generateAdapter = true) @JsonClass(generateAdapter = true)
data class LocationInfo( data class LocationInfo(
/** /**
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30' representing this location. * Required. RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30' representing this location.
*/ */
@Json(name = "uri") val geoUri: String? = null, @Json(name = "uri") val geoUri: String? = null,

View File

@ -35,7 +35,7 @@ data class MessageLocationContent(
@Json(name = "body") override val body: String, @Json(name = "body") override val body: String,
/** /**
* Required. RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30' representing this location. * Required. RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30' representing this location.
*/ */
@Json(name = "geo_uri") val geoUri: String, @Json(name = "geo_uri") val geoUri: String,

View File

@ -708,7 +708,7 @@ internal class LocalEchoEventFactory @Inject constructor(
} }
/** /**
* Returns RFC5870 formatted geo uri 'geo:latitude,longitude;uncertainty' like 'geo:40.05,29.24;30' * Returns RFC5870 formatted geo uri 'geo:latitude,longitude;u=uncertainty' like 'geo:40.05,29.24;u=30'
* Uncertainty of the location is in meters and not required. * Uncertainty of the location is in meters and not required.
*/ */
private fun buildGeoUri(latitude: Double, longitude: Double, uncertainty: Double?): String { private fun buildGeoUri(latitude: Double, longitude: Double, uncertainty: Double?): String {
@ -718,7 +718,7 @@ internal class LocalEchoEventFactory @Inject constructor(
append(",") append(",")
append(longitude) append(longitude)
uncertainty?.let { uncertainty?.let {
append(";") append(";u=")
append(it) append(it)
} }
} }

View File

@ -46,7 +46,7 @@ private const val A_TIMEOUT_MILLIS = 15 * 60 * 1000L
private const val A_LATITUDE = 40.05 private const val A_LATITUDE = 40.05
private const val A_LONGITUDE = 29.24 private const val A_LONGITUDE = 29.24
private const val A_UNCERTAINTY = 30.0 private const val A_UNCERTAINTY = 30.0
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;$A_UNCERTAINTY" private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;u=$A_UNCERTAINTY"
internal class LiveLocationAggregationProcessorTest { internal class LiveLocationAggregationProcessorTest {

View File

@ -30,7 +30,7 @@ data class LocationData(
/** /**
* Creates location data from a MessageLocationContent. * Creates location data from a MessageLocationContent.
* "geo:40.05,29.24;30" -> LocationData(40.05, 29.24, 30) * "geo:40.05,29.24;u=30" -> LocationData(40.05, 29.24, 30)
* @return location data or null if geo uri is not valid * @return location data or null if geo uri is not valid
*/ */
fun MessageLocationContent.toLocationData(): LocationData? { fun MessageLocationContent.toLocationData(): LocationData? {
@ -39,7 +39,7 @@ fun MessageLocationContent.toLocationData(): LocationData? {
/** /**
* Creates location data from a geoUri String. * Creates location data from a geoUri String.
* "geo:40.05,29.24;30" -> LocationData(40.05, 29.24, 30) * "geo:40.05,29.24;u=30" -> LocationData(40.05, 29.24, 30)
* @return location data or null if geo uri is null or not valid * @return location data or null if geo uri is null or not valid
*/ */
fun String?.toLocationData(): LocationData? { fun String?.toLocationData(): LocationData? {

View File

@ -28,19 +28,26 @@ import org.matrix.android.sdk.api.session.room.model.message.MessageLocationCont
class LocationDataTest { class LocationDataTest {
@Test @Test
fun validCases() { fun validCases() {
parseGeo("geo:12.34,56.78;13.56") shouldBeEqualTo parseGeo("geo:12.34,56.78;u=13.56") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
parseGeo("geo:12.34,56.78") shouldBeEqualTo parseGeo("geo:12.34,56.78") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
}
@Test
fun lenientCases() {
// Error is ignored in case of invalid uncertainty // Error is ignored in case of invalid uncertainty
parseGeo("geo:12.34,56.78;13.5z6") shouldBeEqualTo parseGeo("geo:12.34,56.78;u=13.5z6") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
parseGeo("geo:12.34,56.78;13. 56") shouldBeEqualTo parseGeo("geo:12.34,56.78;u=13. 56") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = null)
// Space are ignored (trim) // Space are ignored (trim)
parseGeo("geo: 12.34,56.78;13.56") shouldBeEqualTo parseGeo("geo: 12.34,56.78;u=13.56") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
parseGeo("geo:12.34,56.78; 13.56") shouldBeEqualTo parseGeo("geo:12.34,56.78; u=13.56") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
// missing "u=" for uncertainty is ignored
parseGeo("geo:12.34,56.78;13.56") shouldBeEqualTo
LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56) LocationData(latitude = 12.34, longitude = 56.78, uncertainty = 13.56)
} }
@ -50,17 +57,17 @@ class LocationDataTest {
parseGeo("geo").shouldBeNull() parseGeo("geo").shouldBeNull()
parseGeo("geo:").shouldBeNull() parseGeo("geo:").shouldBeNull()
parseGeo("geo:12.34").shouldBeNull() parseGeo("geo:12.34").shouldBeNull()
parseGeo("geo:12.34;13.56").shouldBeNull() parseGeo("geo:12.34;u=13.56").shouldBeNull()
parseGeo("gea:12.34,56.78;13.56").shouldBeNull() parseGeo("gea:12.34,56.78;u=13.56").shouldBeNull()
parseGeo("geo:12.x34,56.78;13.56").shouldBeNull() parseGeo("geo:12.x34,56.78;u=13.56").shouldBeNull()
parseGeo("geo:12.34,56.7y8;13.56").shouldBeNull() parseGeo("geo:12.34,56.7y8;u=13.56").shouldBeNull()
// Spaces are not ignored if inside the numbers // Spaces are not ignored if inside the numbers
parseGeo("geo:12.3 4,56.78;13.56").shouldBeNull() parseGeo("geo:12.3 4,56.78;u=13.56").shouldBeNull()
parseGeo("geo:12.34,56.7 8;13.56").shouldBeNull() parseGeo("geo:12.34,56.7 8;u=13.56").shouldBeNull()
// Or in the protocol part // Or in the protocol part
parseGeo(" geo:12.34,56.78;13.56").shouldBeNull() parseGeo(" geo:12.34,56.78;u=13.56").shouldBeNull()
parseGeo("ge o:12.34,56.78;13.56").shouldBeNull() parseGeo("ge o:12.34,56.78;u=13.56").shouldBeNull()
parseGeo("geo :12.34,56.78;13.56").shouldBeNull() parseGeo("geo :12.34,56.78;u=13.56").shouldBeNull()
} }
@Test @Test
@ -77,7 +84,7 @@ class LocationDataTest {
@Test @Test
fun unstablePrefixTest() { fun unstablePrefixTest() {
val geoUri = "geo :12.34,56.78;13.56" val geoUri = "aGeoUri"
val contentWithUnstablePrefixes = MessageLocationContent(body = "", geoUri = "", unstableLocationInfo = LocationInfo(geoUri = geoUri)) val contentWithUnstablePrefixes = MessageLocationContent(body = "", geoUri = "", unstableLocationInfo = LocationInfo(geoUri = geoUri))
contentWithUnstablePrefixes.getBestLocationInfo()?.geoUri.shouldBeEqualTo(geoUri) contentWithUnstablePrefixes.getBestLocationInfo()?.geoUri.shouldBeEqualTo(geoUri)

View File

@ -46,7 +46,7 @@ private const val A_LOCATION_TIMESTAMP = 122L
private const val A_LATITUDE = 40.05 private const val A_LATITUDE = 40.05
private const val A_LONGITUDE = 29.24 private const val A_LONGITUDE = 29.24
private const val A_UNCERTAINTY = 30.0 private const val A_UNCERTAINTY = 30.0
private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;$A_UNCERTAINTY" private const val A_GEO_URI = "geo:$A_LATITUDE,$A_LONGITUDE;u=$A_UNCERTAINTY"
class UserLiveLocationViewStateMapperTest { class UserLiveLocationViewStateMapperTest {