Skip to content

Conversation

@hermanschaaf
Copy link
Member

@hermanschaaf hermanschaaf commented Feb 1, 2023

This fixes an edge case in the yaml comment removal code, where environment variables containing only the numbers lost any quotes around them during the yaml -> json -> yaml conversion process. We can force quotes being maintained by making sure the placeholders are replaced by numbers. If they were quoted before, the yaml conversion process will then ensure the quotes remain. In this implementation we use random numbers with a constant seed, so it's spread out but predictable. We also check if the number already occurs in the config (which is incredibly unlikely, but anyway) and choose a different one if so.

Fixes #652

@hermanschaaf hermanschaaf changed the title Fix: handle numbers in env variables fix: Handle numbers in env variables Feb 1, 2023
@github-actions github-actions bot added the fix label Feb 1, 2023
content := envRegex.FindSubmatch(match)[1]
return []byte(openPlaceholder + string(content) + closePlaceholder)
k := fmt.Sprintf("%d", r.Int())
for bytes.Contains(content, []byte(k)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed opportunity to use goto

Copy link
Member

@erezrokah erezrokah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

@github-actions
Copy link

github-actions bot commented Feb 1, 2023

⏱️ Benchmark results

Comparing with beda411

  • DefaultConcurrencyDFS-2 resources/s: 10,689 ⬇️ 1.17% decrease vs. beda411
  • DefaultConcurrencyRoundRobin-2 resources/s: 12,437 ⬆️ 3.80% increase vs. beda411
  • Glob-2 ns/op: 262.1 ⬆️ 6.60% increase vs. beda411
  • TablesWithChildrenDFS-2 resources/s: 25,939 ⬇️ 3.16% decrease vs. beda411
  • TablesWithChildrenRoundRobin-2 resources/s: 23,528 ⬇️ 17.98% decrease vs. beda411
  • TablesWithRateLimitingDFS-2 resources/s: 28.15 ⬇️ 1.14% decrease vs. beda411
  • TablesWithRateLimitingRoundRobin-2 resources/s: 830.6 ⬆️ 0.61% increase vs. beda411
  • BufferedScanner-2 ns/op: 12.16 ⬆️ 7.57% increase vs. beda411
  • LogReader-2 ns/op: 38.83 ⬆️ 4.25% increase vs. beda411

@github-actions github-actions bot added fix and removed fix labels Feb 1, 2023
@codecov-commenter
Copy link

Codecov Report

Base: 47.15% // Head: 47.19% // Increases project coverage by +0.04% 🎉

Coverage data is based on head (78d8363) compared to base (beda411).
Patch coverage: 78.57% of modified lines in pull request are covered.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #651      +/-   ##
==========================================
+ Coverage   47.15%   47.19%   +0.04%     
==========================================
  Files          70       70              
  Lines        6721     6727       +6     
==========================================
+ Hits         3169     3175       +6     
  Misses       3106     3106              
  Partials      446      446              
Impacted Files Coverage Δ
specs/spec_reader.go 68.12% <78.57%> (+1.24%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kodiakhq kodiakhq bot merged commit 0aa8f68 into main Feb 1, 2023
@kodiakhq kodiakhq bot deleted the solve-numbers-in-yaml branch February 1, 2023 15:08
@yevgenypats
Copy link
Contributor

we might want to change the approach instead of yaml->json->yaml just do a small regex removing comments from the yaml . I've a feeling yaml->json->yaml is a place for a lot of such edge cases. but we can do that in the next edge case.

hermanschaaf pushed a commit that referenced this pull request Feb 1, 2023
🤖 I have created a release *beep* *boop*
---


##
[1.33.1](v1.33.0...v1.33.1)
(2023-02-01)


### Bug Fixes

* Handle numbers in env variables
([#651](#651))
([0aa8f68](0aa8f68))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Numbers in environment variables become unquoted

7 participants