Skip to content

Commit bcd65a3

Browse files
committed
check_name: correctly handle "/" in library.properties name value
Previously, when the library.properties name value contained "/", the check incorrectly passed, and only the part of the name value following "/" was checked, because it was assumed to be a path separator.
1 parent ce7e879 commit bcd65a3

File tree

1 file changed

+44
-39
lines changed

1 file changed

+44
-39
lines changed

Diff for: arduino-ci-script.sh

+44-39
Original file line numberDiff line numberDiff line change
@@ -1237,43 +1237,51 @@ ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER=$((ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER +
12371237
readonly ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_INVALID_CHARACTER_EXIT_STATUS=$ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER
12381238
ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER=$((ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER + 1))
12391239
readonly ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_TOO_LONG_EXIT_STATUS=$ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER
1240+
readonly ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_LAST_EXIT_STATUS=$ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER
12401241
# The same folder name restrictions apply to libraries and sketches so this function may be used for both
1241-
function check_folder_name() {
1242-
local -r path="$1"
1243-
# Get the folder name from the path
1244-
local -r folderName="${path##*/}"
1242+
function check_name() {
1243+
local -r name="$1"
12451244

12461245
local exitStatus=$ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS
12471246

12481247
# Starting folder name with a number is only supported by Arduino IDE 1.8.4 and newer
12491248
local -r startsWithNumberRegex="^[0-9]"
1250-
if [[ "$folderName" =~ $startsWithNumberRegex ]]; then
1251-
echo "WARNING: Discouraged folder name: ${folderName}. Folder name beginning with a number is only supported by Arduino IDE 1.8.4 and newer."
1249+
if [[ "$name" =~ $startsWithNumberRegex ]]; then
1250+
echo "WARNING: Discouraged folder name: ${name}. Folder name beginning with a number is only supported by Arduino IDE 1.8.4 and newer."
12521251
fi
12531252

12541253
# Starting folder name with a - or . is not allowed
12551254
local -r startsWithInvalidCharacterRegex="^[-.]"
1256-
if [[ "$folderName" =~ $startsWithInvalidCharacterRegex ]]; then
1257-
echo "Invalid folder name: ${folderName}. Folder name beginning with a - or . is not allowed."
1255+
if [[ "$name" =~ $startsWithInvalidCharacterRegex ]]; then
1256+
echo "Invalid folder name: ${name}. Folder name beginning with a - or . is not allowed."
12581257
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_INVALID_FIRST_CHARACTER_EXIT_STATUS)
12591258
fi
12601259

12611260
# Allowed characters: a-z, A-Z, 0-1, -._
12621261
local -r disallowedCharactersRegex="[^a-zA-Z0-9._-]"
1263-
if [[ "$folderName" =~ $disallowedCharactersRegex ]]; then
1264-
echo "Invalid folder name: ${folderName}. Only letters, numbers, dots, dashes, and underscores are allowed."
1262+
if [[ "$name" =~ $disallowedCharactersRegex ]]; then
1263+
echo "Invalid folder name: ${name}. Only letters, numbers, dots, dashes, and underscores are allowed."
12651264
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_INVALID_CHARACTER_EXIT_STATUS)
12661265
fi
12671266

12681267
# <64 characters
1269-
if [[ ${#folderName} -gt 63 ]]; then
1270-
echo "Folder name $folderName exceeds the maximum of 63 characters."
1268+
if [[ ${#name} -gt 63 ]]; then
1269+
echo "Folder name $name exceeds the maximum of 63 characters."
12711270
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_TOO_LONG_EXIT_STATUS)
12721271
fi
12731272
return "$exitStatus"
12741273
}
12751274

1276-
ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER=1
1275+
function check_folder_name() {
1276+
local -r path="$1"
1277+
# Get the folder name from the path
1278+
local -r folderName="${path##*/}"
1279+
1280+
check_name "$folderName"
1281+
return "$?"
1282+
}
1283+
1284+
ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER=$((ARDUINO_CI_SCRIPT_CHECK_FOLDER_NAME_LAST_EXIT_STATUS + 1))
12771285
readonly ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS=$ARDUINO_CI_SCRIPT_EXIT_STATUS_COUNTER
12781286
function check_library_properties_name() {
12791287
local -r name="$1"
@@ -1288,6 +1296,13 @@ function check_library_properties_name() {
12881296
if [[ "${name,,}" =~ $ReservedNameRegex ]] && ! [[ "$name" =~ $GrandfatheredNameRegex ]]; then
12891297
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS)
12901298
fi
1299+
1300+
# Library Manager installs libraries to a folder that is the name field value with any spaces replaced with _
1301+
local -r libraryManagerFolderName="${name// /_}"
1302+
1303+
check_name "$libraryManagerFolderName"
1304+
exitStatus=$(set_exit_status "$exitStatus" $?)
1305+
12911306
return "$exitStatus"
12921307
}
12931308

@@ -1750,19 +1765,14 @@ function check_library_properties() {
17501765
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_BLANK_NAME_EXIT_STATUS)
17511766
else
17521767
# Check for invalid name value
1753-
# Library Manager installs libraries to a folder that is the name field value with any spaces replaced with _
1754-
local libraryManagerFolderName="${nameValue// /_}"
1755-
check_folder_name "$libraryManagerFolderName"
1756-
local checkFolderNameExitStatus=$?
1757-
if [[ $checkFolderNameExitStatus -ne $ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS ]]; then
1758-
echo "WARNING: ${normalizedLibraryPropertiesPath}/library.properties: name value: $nameValue does not meet the requirements of the Arduino Library Manager indexer. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format"
1759-
fi
1760-
1761-
# Check if the library.properties name value starts with "arduino" (case-insensitive)
17621768
check_library_properties_name "$nameValue"
17631769
local checkLibraryPropertiesNameExitStatus=$?
1764-
if [[ "$checkLibraryPropertiesNameExitStatus" == "$ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS" ]]; then
1765-
echo "WARNING: ${normalizedLibraryPropertiesPath}/library.properties: name value: $nameValue starts with \"arduino\". These names are reserved for official Arduino libraries. Libraries using a reserved name will not be accepted in the Library Manager index."
1770+
if [[ $checkLibraryPropertiesNameExitStatus -ne $ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS ]]; then
1771+
if [[ "$checkLibraryPropertiesNameExitStatus" == "$ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS" ]]; then
1772+
echo "WARNING: ${normalizedLibraryPropertiesPath}/library.properties: name value: $nameValue starts with \"arduino\". These names are reserved for official Arduino libraries. Libraries using a reserved name will not be accepted in the Library Manager index."
1773+
else
1774+
echo "WARNING: ${normalizedLibraryPropertiesPath}/library.properties: name value: $nameValue does not meet the requirements of the Arduino Library Manager indexer. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format"
1775+
fi
17661776
fi
17671777
fi
17681778
fi
@@ -2368,22 +2378,17 @@ function check_library_manager_compliance() {
23682378
local nameValue
23692379
nameValue="$(get_library_properties_field_value "$libraryProperties" 'name')"
23702380

2371-
# Check for characters in the library.properties name value disallowed by the Library Manager indexer
2372-
# Library Manager installs libraries to a folder that is the name field value with any spaces replaced with _
2373-
local -r libraryManagerFolderName="${nameValue// /_}"
2374-
check_folder_name "$libraryManagerFolderName"
2375-
local -r checkFolderNameExitStatus=$?
2376-
if [[ $checkFolderNameExitStatus -ne $ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS ]]; then
2377-
echo "ERROR: ${normalizedLibraryPath}/library.properties: name value: $nameValue does not meet the requirements of the Arduino Library Manager indexer. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format"
2378-
exitStatus=$(set_exit_status "$exitStatus" $((ARDUINO_CI_SCRIPT_CHECK_LIBRARY_MANAGER_COMPLIANCE_CHECK_FOLDER_NAME_OFFSET + checkFolderNameExitStatus)))
2379-
fi
2380-
2381-
# Check if the library.properties name value starts with "arduino" (case-insensitive)
2381+
# Check if the library.properties name value meets the requirements of the Library Manager indexer
23822382
check_library_properties_name "$nameValue"
2383-
local checkLibraryPropertiesNameExitStatus=$?
2384-
if [[ "$checkLibraryPropertiesNameExitStatus" == "$ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS" ]]; then
2385-
echo "ERROR: ${normalizedLibraryPath}/library.properties: name value: $nameValue starts with \"arduino\". These names are reserved for official Arduino libraries."
2386-
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_LIBRARY_MANAGER_COMPLIANCE_NAME_IS_RESERVED_EXIT_STATUS)
2383+
local -r checkLibraryPropertiesNameExitStatus=$?
2384+
if [[ $checkLibraryPropertiesNameExitStatus -ne $ARDUINO_CI_SCRIPT_SUCCESS_EXIT_STATUS ]]; then
2385+
if [[ "$checkLibraryPropertiesNameExitStatus" == "$ARDUINO_CI_SCRIPT_CHECK_LIBRARY_PROPERTIES_NAME_RESERVED_NAME_EXIT_STATUS" ]]; then
2386+
echo "ERROR: ${normalizedLibraryPath}/library.properties: name value: $nameValue starts with \"arduino\". These names are reserved for official Arduino libraries."
2387+
exitStatus=$(set_exit_status "$exitStatus" $ARDUINO_CI_SCRIPT_CHECK_LIBRARY_MANAGER_COMPLIANCE_NAME_IS_RESERVED_EXIT_STATUS)
2388+
else
2389+
echo "ERROR: ${normalizedLibraryPath}/library.properties: name value: $nameValue does not meet the requirements of the Arduino Library Manager indexer. See: https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format"
2390+
exitStatus=$(set_exit_status "$exitStatus" $((ARDUINO_CI_SCRIPT_CHECK_LIBRARY_MANAGER_COMPLIANCE_CHECK_FOLDER_NAME_OFFSET + checkLibraryPropertiesNameExitStatus)))
2391+
fi
23872392
fi
23882393

23892394
local urlValue

0 commit comments

Comments
 (0)