Skip to content

Commit

Permalink
[ef-core]: Fix RIDER-112371: Relax rules for appsettings.json and `…
Browse files Browse the repository at this point in the history
…secrets.json` parsing, allow trailing commas
  • Loading branch information
seclerp committed Aug 7, 2024
1 parent 7ae507a commit 4ffae4f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class AppSettingsConnectionProvider(private val intellijProject: Project) : DbCo

override fun getAvailableConnections(project: RdProjectDescriptor) =
buildList {
val directory = (project.location as RdCustomLocation?)?.customLocation?.let(::Path)?.parent ?: return@buildList
val directory = (project.location as? RdCustomLocation)?.customLocation?.let(::Path)?.parent ?: return@buildList
@NonNls
val connectionStrings = directory.listDirectoryEntries("appsettings*.json")
.filter { it.isRegularFile() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class JsonConnectionStringsManager(intellijProject: Project) {
* }
*/
private fun getConnectionsFromObject(fileName: String, jsonFile: JsonNode): List<DbConnectionInfo> = buildList {
val obj = jsonFile.get("ConnectionStrings") as ObjectNode? ?: return emptyList()
val obj = jsonFile.get("ConnectionStrings") as? ObjectNode ?: return emptyList()
obj.fieldNames().forEach { connName ->
val connString = (obj[connName] as TextNode?)?.textValue()
val connString = (obj[connName] as? TextNode)?.textValue()
if (connString != null)
add(DbConnectionInfo(connName, connString, fileName, null))
}
Expand All @@ -53,7 +53,7 @@ class JsonConnectionStringsManager(intellijProject: Project) {
null -> return@forEach
else -> {
val name = match.groups["name"]?.value ?: return@forEach
val connection = (jsonFile[settingsField] as TextNode?)?.textValue() ?: return@forEach
val connection = (jsonFile[settingsField] as? TextNode)?.textValue() ?: return@forEach
add(DbConnectionInfo(name, connection, fileName, null))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jetbrains.rider.plugins.efcore.features.shared.services

import com.fasterxml.jackson.core.JacksonException
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.core.json.JsonReadFeature
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.intellij.openapi.components.Service
Expand All @@ -17,6 +18,7 @@ class JsonSerializer {
jacksonObjectMapper()
.enable(JsonParser.Feature.ALLOW_COMMENTS)
.enable(JsonParser.Feature.ALLOW_SINGLE_QUOTES)
.enable(JsonReadFeature.ALLOW_TRAILING_COMMA.mappedFeature())

fun getInstance() = service<JsonSerializer>()
}
Expand Down

0 comments on commit 4ffae4f

Please sign in to comment.