Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generation/apply_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ trap 'rm -f "$SED_SCRIPT_FILE"' EXIT
for KV in $(cut -f1,"${column_index}" -d: $versions_file |grep -v "#"); do
K=${KV%:*}; V=${KV#*:}
echo Key:$K, Value:$V;
echo "/x-version-update:$K:current/{s|<version>.*<\/version>|<version>$V<\/version>|;}" >> "$SED_SCRIPT_FILE"
echo '/x-version-update:'"$K"':current/{s|<\([^>]*\)>[^<]*</\1>|<\1>'"$V"'</\1>|;}' >> "$SED_SCRIPT_FILE"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Issue: Potential XML Corruption on Lines with Multiple Tags

The current regular expression <\([^>]*\)>[^<]*</\1> matches the first leaf XML tag on the line, regardless of whether it is the tag intended for the version update.

If a line contains multiple tags (for example, a dependency definition on a single line or multiple properties), like:

<groupId>com.google.cloud</groupId> <version>1.0.0</version> <!-- x-version-update:my-dep:current -->

The regex will match <groupId>com.google.cloud</groupId> instead of <version>1.0.0</version>, resulting in the corruption of the groupId tag:

<groupId>1.2.3</groupId> <version>1.0.0</version> <!-- x-version-update:my-dep:current -->

Solution: Anchor the Match to the Comment

We can prevent this by anchoring the match to the specific x-version-update comment on the same line, ensuring that no other tags (i.e., no < characters) exist between the closing tag and the comment. This guarantees that only the tag immediately preceding the comment is updated.

Suggested change
echo '/x-version-update:'"$K"':current/{s|<\([^>]*\)>[^<]*</\1>|<\1>'"$V"'</\1>|;}' >> "$SED_SCRIPT_FILE"
echo '/x-version-update:'"$K"':current/{s|<\([^>]*\)>[^<]*</\1>\([^<]*x-version-update:'"$K"':current\)|<\1>'"$V"'</\1>\2|;}' >> "$SED_SCRIPT_FILE"

done

echo "Running sed command. It may take few minutes."
Expand Down
Loading