Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ef-core]: Fix RIDER-112371: Relax rules for appsettings.json and secrets.json parsing, allow trailing commas #228

Merged
merged 1 commit into from
Aug 7, 2024
Merged
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 @@ -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
Loading