Skip to content

Escape > in defines#441

Closed
jthuangarm wants to merge 1 commit intoOpen-CMSIS-Pack:mainfrom
jthuangarm:main
Closed

Escape > in defines#441
jthuangarm wants to merge 1 commit intoOpen-CMSIS-Pack:mainfrom
jthuangarm:main

Conversation

@jthuangarm
Copy link
Collaborator

Fixes

Changes

  • Replace > by $<ANGLE-R>

Checklist

  • 🤖 This change is covered by unit tests (if applicable).
  • 🤹 Manual testing has been performed (if necessary).
  • 🛡️ Security impacts have been considered (if relevant).
  • 📖 Documentation updates are complete (if required).
  • 🧠 Third-party dependencies and TPIP updated (if required).

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where the > character in define values was not being escaped for use inside CMake generator expressions. CMake generator expressions (like $<$<COMPILE_LANGUAGE:C,CXX>:...>) interpret unescaped > as a closing delimiter, causing broken output such as -D> -DRANDOM_CONFIG_FILE="\"<random_config.h\"". The fix replaces > with $<ANGLE-R> in ListCompileDefinitions. The PR also updates a broken GolangCI-Lint installation URL in DEVELOPING.md.

Changes:

  • Replace > with $<ANGLE-R> in define values within ListCompileDefinitions to correctly escape the character inside CMake generator expressions.
  • Add a unit test for the > escaping behavior in buildcontent_test.go.
  • Update the GolangCI-Lint installation URL in DEVELOPING.md to the current path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
pkg/maker/buildcontent.go Adds strings.ReplaceAll to escape > as $<ANGLE-R> in define values
pkg/maker/buildcontent_test.go Adds test verifying > characters are escaped to $<ANGLE-R>
DEVELOPING.md Updates GolangCI-Lint install URL to the new documentation path

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -308,6 +308,7 @@ func ListCompileDefinitions(defines []interface{}, delimiter string) string {
key, value := utils.GetDefine(define)
pair := key
if len(value) > 0 {
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The fix only escapes > but not <. According to the CMake generator expression documentation, < inside a generator expression value would be interpreted as the start of a nested generator expression (e.g., $< introduces one). The original issue example uses RANDOM_CONFIG_FILE: \"<random_config.h>\" — the < in <random_config.h> would also cause problems inside $<$<COMPILE_LANGUAGE:C,CXX>:...>. CMake provides $<ANGLE-L> as the escape for <, analogous to $<ANGLE-R> for >. Both characters should be escaped to correctly handle defines like RANDOM_CONFIG_FILE="<random_config.h>".

A second ReplaceAll call should be added to replace < with $<ANGLE-L> before the existing > replacement (since $<ANGLE-R> itself contains >, the order matters: replace < first, then replace >).

Suggested change
if len(value) > 0 {
if len(value) > 0 {
value = strings.ReplaceAll(value, "<", "$<ANGLE-L>")

Copilot uses AI. Check for mistakes.
map[string]interface{}{"FOO": "A>B>C"},
}
assert.Equal("FOO=A$<ANGLE-R>B$<ANGLE-R>C", maker.ListCompileDefinitions(defines, ";"))
})
Copy link

Copilot AI Mar 10, 2026

Choose a reason for hiding this comment

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

The test only covers the > escaping case. Since < should also be escaped (as $<ANGLE-L>) inside CMake generator expressions, a test case for < escaping (and ideally combined <..> like the original issue's \"<random_config.h>\") should also be included to match the fix and provide regression coverage.

Suggested change
})
})
t.Run("test escape left angle bracket", func(t *testing.T) {
defines := []interface{}{
map[string]interface{}{"FOO": "A<B<C"},
}
assert.Equal("FOO=A$<ANGLE-L>B$<ANGLE-L>C", maker.ListCompileDefinitions(defines, ";"))
})
t.Run("test escape include style angle brackets", func(t *testing.T) {
defines := []interface{}{
map[string]interface{}{"INCLUDE": "\"<random_config.h>\""},
}
assert.Equal("INCLUDE=\"$<ANGLE-L>random_config.h$<ANGLE-R>\"", maker.ListCompileDefinitions(defines, ";"))
})

Copilot uses AI. Check for mistakes.
@jthuangarm jthuangarm closed this Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants