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

Invalid escape sequence in literal since 6.6.2 #1073

Open
gierunio opened this issue Aug 31, 2023 · 3 comments
Open

Invalid escape sequence in literal since 6.6.2 #1073

gierunio opened this issue Aug 31, 2023 · 3 comments

Comments

@gierunio
Copy link

gierunio commented Aug 31, 2023

I use .strings files for country-based regular expressions like postal code validation. Since the fallback attribute was introduced in 6.6.x, I get "Invalid escape sequence in literal" compiler error for strings like "^[a-zA-Z0-9\\/]*$" which is replaced with "^[a-zA-Z0-9\/]*$" for the fallback value.

@Liquidsoul
Copy link
Member

Could you provide more inputs on this? Like your configuration or some sample code to reproduce this issue?

@gierunio
Copy link
Author

gierunio commented Oct 26, 2023

Here is an example project:
SwiftGenExample.zip

I have Localizable.strings file with content:

"postal_code" = "^[0-9]{2}-[0-9]{3}$";
"phone_number" = "^(\\+?48\\s?)?[0-9]{3}\\s?[0-9]{3}\\s?[0-9]{3}$";
"house_number_and_suite" = "^[a-zA-Z0-9\\/]*$";

SwiftGen produces:

internal enum Localized {
  /// ^[a-zA-Z0-9\/]*$
  internal static var houseNumberAndSuite: String { return Localized.tr("Localizable", "house_number_and_suite", fallback: "^[a-zA-Z0-9\/]*$") }
  /// ^(\+?48\s?)?[0-9]{3}\s?[0-9]{3}\s?[0-9]{3}$
  internal static var phoneNumber: String { return Localized.tr("Localizable", "phone_number", fallback: "^(\+?48\s?)?[0-9]{3}\s?[0-9]{3}\s?[0-9]{3}$") }
  /// ^[0-9]{2}-[0-9]{3}$
  internal static var postalCode: String { return Localized.tr("Localizable", "postal_code", fallback: "^[0-9]{2}-[0-9]{3}$") }
}

And I get "Invalid escape sequence in literal" error for the first two strings.
Version 6.5.1 of SwiftGen works just fine, because there is no third parameter with the default value in the tr function.

@Sc4pego4t
Copy link

I get the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants