Skip to content

Substituion issue in 2.6.3 #296

@Isakdl

Description

@Isakdl

I'm a maintainer of https://serverpod.dev, and we use this library internally to make SQL queries.

First of I understand that the 3.0 interface has changed substantially, we want to migrate to version 3 but it requires some breaking changes in our API's and we are working on making this transition already. But we would still like to fix this issue in our current live version.

However, we encountered a problem where users supplying a string containing "@sometext:" gets a format exception because the "substitution" string does not contain a type. This happens even though we do not supply any substitutions to the query.

Would it be possible to get a patch for the 2.6 version with a fix for this?

All that would be needed is to not run the substitution logic if no substitutions are supplied. I.e this change in the file lib/src/substituter.dart for method substitute on line 20.

// substituter.dart

static String substitute(String fmtString, Map<String, dynamic>? values,
      {SQLReplaceIdentifierFunction? replace}) {
    if (values == null || values.isEmpty) return fmtString; // <- add this line

    final converter = PostgresTextEncoder();
    values ??= const {};
    replace ??= (spec, index) => converter.convert(values![spec.name]);
  
    ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions