Fix symbol validation - prevent empty symbol codes
Added validation to ensure all packets with positions have valid symbols: - symbol_code must be exactly 1 character, defaults to '>' (car) if missing - symbol_table_id must be exactly 1 character, defaults to '/' if missing - Validation only applies to packets with positions Fixed 5 existing packets with empty symbol codes that would have caused display issues on the map. This prevents errors when rendering APRS symbols and ensures all positioned packets can be displayed correctly.
This commit is contained in:
parent
3ebcbfc78d
commit
ae8f2acc48
1 changed files with 33 additions and 0 deletions
|
|
@ -147,6 +147,39 @@ defmodule Aprsme.Packet do
|
|||
changeset
|
||||
|> maybe_create_geometry_from_lat_lon()
|
||||
|> maybe_set_has_position()
|
||||
|> normalize_symbols()
|
||||
end
|
||||
|
||||
defp normalize_symbols(changeset) do
|
||||
# Only normalize if packet has position
|
||||
if get_field(changeset, :has_position) do
|
||||
symbol_code = get_field(changeset, :symbol_code)
|
||||
symbol_table_id = get_field(changeset, :symbol_table_id)
|
||||
|
||||
changeset
|
||||
|> normalize_symbol_code(symbol_code)
|
||||
|> normalize_symbol_table_id(symbol_table_id)
|
||||
else
|
||||
changeset
|
||||
end
|
||||
end
|
||||
|
||||
defp normalize_symbol_code(changeset, code) when is_binary(code) and byte_size(code) == 1 do
|
||||
changeset
|
||||
end
|
||||
|
||||
defp normalize_symbol_code(changeset, _invalid_code) do
|
||||
# Default to '>' (car) if symbol_code is missing or invalid
|
||||
put_change(changeset, :symbol_code, ">")
|
||||
end
|
||||
|
||||
defp normalize_symbol_table_id(changeset, table) when is_binary(table) and byte_size(table) == 1 do
|
||||
changeset
|
||||
end
|
||||
|
||||
defp normalize_symbol_table_id(changeset, _invalid_table) do
|
||||
# Default to '/' (primary symbol table) if table_id is missing or invalid
|
||||
put_change(changeset, :symbol_table_id, "/")
|
||||
end
|
||||
|
||||
@spec maybe_create_geometry_from_lat_lon(Ecto.Changeset.t()) :: Ecto.Changeset.t()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue