Skip to content

Commit

Permalink
Merge pull request #118 from dailymotion/be-more-strict-with-omsdk-ve…
Browse files Browse the repository at this point in the history
…rification-scripts

Be more strict with OMSDK verificationScripts parsing
  • Loading branch information
michgauz committed Oct 26, 2021
2 parents cb91441 + 8722bec commit 774136f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
2 changes: 2 additions & 0 deletions sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ dependencies {
implementation("androidx.core:core-ktx:1.5.0")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.10")
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))

testImplementation("junit:junit:4.13.2")
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,22 +311,22 @@ object OMHelper {
/**
* Parse the verificationScriptsList from the payload of AdLoadedEvent
*/
private fun parseVerificationScriptData(payload: String?): List<VerificationScriptData> {
internal fun parseVerificationScriptData(payload: String?): List<VerificationScriptData> {
return payload
?.split("&")
?.groupBy {
val m = Pattern.compile("verificationScripts\\[(.*)]\\[(.*)]=(.*)").matcher(it)
val m = Pattern.compile("verificationScripts\\[([0-9]*)]\\[(.*)]=(.*)").matcher(it)
if (m.matches()) m.group(1) else null
}
?.filterKeys { it != null }
?.map { group ->
VerificationScriptData(
vendorKey = group.value.find { it.contains("verificationScripts[${group.key}][vendor]") }
?.split("=")?.get(1) ?: "",
?.split("=", limit = 2)?.get(1) ?: "",
url = group.value.find { it.contains("verificationScripts[${group.key}][resource]") }
?.split("=")?.get(1) ?: "",
?.split("=", limit = 2)?.get(1) ?: "",
parameters = group.value.find { it.contains("verificationScripts[${group.key}][parameters]") }
?.split("=")?.get(1) ?: ""
?.split("=", limit = 2)?.get(1) ?: ""
)
}
?: emptyList()
Expand Down

0 comments on commit 774136f

Please sign in to comment.