Fixed uninitialized string offset error in labels in new label engine when field label was blank #14404
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I haven't been able to see this happening in the wild, but I do see it on the demos. Should hopefully fix RB-3750Okay, this took a bit to track down, with the added bonus of being really hard to explain. For the purposes of this, "Asset Label" is the full asset label that gets printed out. "Field Label" refers to the label on the fields the user has selected that should appear on the Asset Label.
tldr;
Potentially breaking change
Because we no longer shorten the label for you, and have removed the automatic colon, users may need to update their label settings to use just the first letter and the colon manually if that's what you want displayed on the Asset Labels.
Full Explanation
This error (
ErrorException: Uninitialized string offset 0 in /home/serverpilot/apps/demo.snipeitapp.com/snipe-it/app/Models/Labels/DefaultLabel.php:169
) was occurring if a user added fields in the Field Definitions but the Field Label for those fields was left blank.The quick workaround for this currently is below:
However that's dumb and people shouldn't have to do this.
That particular error was triggering because in the code, we were using
$field['label'][0]
(for some reason) which would take just the first character of the Field Label - I presume to save space on small labels. I don't think we should be making that decision for people, however. If they want the first letter only, they can enter that as the Field Label.When presented with a string with an array-type addition, for example
$string[0]
where$string
is definitely a string and not an array, that array-treatment will pick the 0th character in the string. Likewise,$string[1]
would pick the second character from the string (because the string array is 0-based array), and so on.The error was being triggered because you can't pick the first character from a blank string.
This may mean that folks will need to go back into their label settings and change something like "Company Name" to "C:" if that's what they want on their labels, however this is far more correct, IMHO, and it's an easy enough setting to change.
Fixed RB-17914 and RB-17913