From bb86f764a224cc6aac3986ecc793556d0dc32af5 Mon Sep 17 00:00:00 2001 From: Ushakov Michale Date: Tue, 12 Nov 2024 23:57:01 +0500 Subject: [PATCH 1/4] test reproducing the issue --- formatter_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/formatter_test.go b/formatter_test.go index 0ea7804..7afc0c6 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -113,6 +113,11 @@ func TestFormat(t *testing.T) { }, expected: "Example is: {123 This is a test str, nothing more special -1.098743 main question error, is 42}", }, + "open bracket at the end of line of go file": { + template: "type serviceHealth struct {", + args: []any{}, + expected: "type serviceHealth struct {", + }, } { t.Run(name, func(t *testing.T) { assert.Equal(t, test.expected, stringFormatter.Format(test.template, test.args...)) From a890a485be2cad894cf7e0b52e592348a38cc0f4 Mon Sep 17 00:00:00 2001 From: Ushakov Michale Date: Tue, 12 Nov 2024 23:59:50 +0500 Subject: [PATCH 2/4] and 1 more test with same issue -> FormatComplex --- formatter_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/formatter_test.go b/formatter_test.go index 7afc0c6..4d4b2c5 100644 --- a/formatter_test.go +++ b/formatter_test.go @@ -197,6 +197,11 @@ func TestFormatComplex(t *testing.T) { args: map[string]any{"ipaddr": "127.0.0.1", "port": 5432, "ssl": false}, expected: "Current app settings are: ipAddr: 127.0.0.1, port: 5432, use ssl: false.", }, + "one json line with open bracket at the end": { + template: " \"server\": {", + args: map[string]any{}, + expected: " \"server\": {", + }, } { t.Run(name, func(t *testing.T) { assert.Equal(t, test.expected, stringFormatter.FormatComplex(test.template, test.args)) From 7f13715b14433a06e0f5babdda0ffcda86efa995 Mon Sep 17 00:00:00 2001 From: Ushakov Michale Date: Wed, 13 Nov 2024 12:47:52 +0500 Subject: [PATCH 3/4] fixing { disapper at the end of line --- formatter.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/formatter.go b/formatter.go index 1859300..ed92301 100644 --- a/formatter.go +++ b/formatter.go @@ -44,6 +44,9 @@ func Format(template string, args ...any) string { if template[i] == '{' { // possibly it is a template placeholder if i == templateLen-1 { + // if we gave { at the end of line i.e. -> type serviceHealth struct {, + // without this write we got type serviceHealth struct + formattedStr.WriteByte('{') break } // considering in 2 phases - {{ }} @@ -156,6 +159,9 @@ func FormatComplex(template string, args map[string]any) string { if template[i] == '{' { // possibly it is a template placeholder if i == templateLen-1 { + // if we gave { at the end of line i.e. -> type serviceHealth struct {, + // without this write we got type serviceHealth struct + formattedStr.WriteByte('{') break } From a679eb2826b33f8d04b80890942d5421a1fd3653 Mon Sep 17 00:00:00 2001 From: Ushakov Michale Date: Wed, 13 Nov 2024 13:03:42 +0500 Subject: [PATCH 4/4] version update to 1.2.1 in readme --- README.md | 5 ++--- formatter.go | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9603961..4699189 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ # StringFormatter -A set of a ***high performance string tools*** that helps to build strings from templates and process text that -faster than `fmt`!!!. +A set of a ***high performance string tools*** that helps to build strings from templates and process text faster than with `fmt`!!!. ![GitHub go.mod Go version (subdirectory of monorepo)](https://img.shields.io/github/go-mod/go-version/wissance/stringFormatter?style=plastic) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wissance/stringFormatter?style=plastic) ![GitHub issues](https://img.shields.io/github/issues/wissance/stringFormatter?style=plastic) ![GitHub Release Date](https://img.shields.io/github/release-date/wissance/stringFormatter) -![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.2.0/total?style=plastic) +![GitHub release (latest by date)](https://img.shields.io/github/downloads/wissance/stringFormatter/v1.2.1/total?style=plastic) ![String Formatter: a convenient string formatting tool](/img/sf_cover.png) diff --git a/formatter.go b/formatter.go index ed92301..c0b1e1a 100644 --- a/formatter.go +++ b/formatter.go @@ -160,7 +160,7 @@ func FormatComplex(template string, args map[string]any) string { // possibly it is a template placeholder if i == templateLen-1 { // if we gave { at the end of line i.e. -> type serviceHealth struct {, - // without this write we got type serviceHealth struct + // without this write we got type serviceHealth struct formattedStr.WriteByte('{') break }