diff --git a/.php-cs-fixer.cache b/.php-cs-fixer.cache new file mode 100644 index 0000000..521368b --- /dev/null +++ b/.php-cs-fixer.cache @@ -0,0 +1 @@ +{"php":"8.4.18","version":"3.95.3:v3.95.3#3d681493acc0e93283481b1c63c263737df78687","indent":" ","lineEnding":"\n","rules":{"align_multiline_comment":{"comment_type":"phpdocs_only"},"array_indentation":true,"array_syntax":{"syntax":"short"},"binary_operator_spaces":{"default":"single_space"},"blank_line_before_statement":{"statements":["if","return","while","for","foreach","do"]},"blank_line_after_opening_tag":true,"blank_line_after_namespace":true,"full_opening_tag":true,"fully_qualified_strict_types":true,"line_ending":true,"linebreak_after_opening_tag":true,"lowercase_cast":true,"lowercase_keywords":true,"lowercase_static_reference":true,"no_alternative_syntax":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_blank_lines_before_namespace":true,"no_closing_tag":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_multiline_whitespace_around_double_arrow":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_unused_imports":true,"single_import_per_statement":true,"single_blank_line_at_eof":true,"no_whitespace_in_blank_line":true,"ordered_imports":{"sort_algorithm":"alpha"},"ordered_class_elements":{"sort_algorithm":"alpha","order":["constant_public","constant_protected","constant_private","property_public","property_protected","property_private","construct","method_public","method_private"]},"no_mixed_echo_print":{"use":"echo"},"constant_case":{"case":"lower"},"increment_style":{"style":"post"},"concat_space":{"spacing":"none"},"braces":{"allow_single_line_closure":false,"position_after_functions_and_oop_constructs":"same","position_after_anonymous_constructs":"next","position_after_control_structures":"same"},"class_definition":{"single_line":true}},"ruleCustomisationPolicyVersion":"null-policy","hashes":{"WebFiori\/Ui\/ListItem.php":"ea7d937d7f0f87b387231e19f408bac4","WebFiori\/Ui\/Input.php":"a32571b47302e88abe1a1b593f05c580","WebFiori\/Ui\/Exceptions\/TemplateNotFoundException.php":"0525fa91afe1452e9e2cb3817a5d20d0","WebFiori\/Ui\/Exceptions\/InvalidNodeNameException.php":"34dcd7ac55b28f1038b910cf4b1d6294","WebFiori\/Ui\/TemplateCompiler.php":"a7729de8052c9b71d8d6eda1da60f18d","WebFiori\/Ui\/TableRow.php":"c6dfd353a53a6b1ea0fa373cabf6ac99","WebFiori\/Ui\/Br.php":"874d09a7145347cbdbac3f893272bc4e","WebFiori\/Ui\/JsCode.php":"a70c5cabef6bd72ee89a55b10f88fead","WebFiori\/Ui\/Label.php":"408765b9d4a663229900d37e95c4e11d","WebFiori\/Ui\/HTMLList.php":"bcdc411a01b7ebc745e46a36b6871162","WebFiori\/Ui\/TableCell.php":"c622079f8a69e271fbcbcdb2b8e5fbf4","WebFiori\/Ui\/HTMLTable.php":"2d3cf67e93ab3e465cc5c57efe107cce","WebFiori\/Ui\/HeadNode.php":"d6ca40f301ba32df712304ff3d43d294","WebFiori\/Ui\/RadioGroup.php":"eaa8804e05590ad82ca3d7ffd3ec48c6","WebFiori\/Ui\/HTMLNode.php":"3fbee82bf49c0982ec60c94737c8dab7","WebFiori\/Ui\/Anchor.php":"d037b740c3115c48c44d92a296c50f6b","WebFiori\/Ui\/UnorderedList.php":"7f4c6f8b415392a764b1ab116c89ad90","WebFiori\/Ui\/OrderedList.php":"ed8d4fd70121b5d6411acf0a42604c91","WebFiori\/Ui\/HTMLDoc.php":"680405abb4862b29f467211bcc83afec","WebFiori\/Ui\/CodeSnippet.php":"c4cd75c3cf5d61d065160401d8198c3b","WebFiori\/Ui\/Paragraph.php":"779c96103576311cec2b08e20c229c1a"}} \ No newline at end of file diff --git a/WebFiori/Ui/Anchor.php b/WebFiori/Ui/Anchor.php index 4920d0d..06a7b4c 100644 --- a/WebFiori/Ui/Anchor.php +++ b/WebFiori/Ui/Anchor.php @@ -1,4 +1,5 @@ parseStylePair($current, $retVal); + $current = ''; + } else { + $current .= $ch; + } + } + + if (trim($current) !== '') { + $this->parseStylePair($current, $retVal); } return $retVal; @@ -1651,7 +1670,7 @@ public function open() : string { $valType = gettype($val); $quoted = $this->isQuotedAttribute(); - if (!$quoted && $valType == "integer" || $valType == 'double') { + if (!$quoted && ($valType == "integer" || $valType == 'double')) { $retVal .= ' '.$attr.'='.$val; } else { if ($val != '' && !$quoted && strpos($val, '?') === false @@ -1661,7 +1680,7 @@ public function open() : string { && strpos($val, '-') === false) { $retVal .= ' '.$attr.'='.$val; } else { - $retVal .= ' '.$attr.'="'.str_replace('"', '\"', $val).'"'; + $retVal .= ' '.$attr.'="'.str_replace(['&', '"'], ['&', '"'], $val).'"'; } } } @@ -1910,15 +1929,18 @@ public function setAttribute(string $name, mixed $val = null) : HTMLNode { } else if ($val === null) { $this->attributes[$trimmedName] = null; } else if ($attrValType == 'string') { - $this->attributes[$trimmedName] = $trimmedVal; + $this->attributes[$trimmedName] = $trimmedVal; } else if (in_array($attrValType, ['double', 'integer'])) { $this->attributes[$trimmedName] = $val; } else if ($attrValType == 'boolean') { $this->attributes[$trimmedName] = $val === true ? 'true' : 'false'; } + } else { + throw new \InvalidArgumentException("Invalid attribute name: '$trimmedName'."); } } + return $this; } /** @@ -2494,7 +2516,6 @@ private function closeAsCode(array $FO) : string { } else { return '</'.$this->getNodeName().'>'; } - } /** * @@ -2640,6 +2661,32 @@ private function openAsCode(array $FO) : string { return $retVal; } + /** + * Validates the name of the node. + * + * @param string $name The name of the node in lower case. + * + * @return bool If the name is valid, the method will return true. If + * it is not valid, it will return false. Valid values must follow the + * following rules: + *