dsuhinin commented on code in PR #76018:
URL: https://github.com/apache/airflow/pull/76018#discussion_r4425444016


##########
airflow-core/src/airflow/ui/src/components/FlexibleForm/parseArrayElement.ts:
##########
@@ -0,0 +1,62 @@
+/*!
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+export type ArrayElement = boolean | number | string;
+
+/**
+ * Parse one typed-in entry to the element type from `items.type`; `undefined` 
means invalid.
+ * Without an `items.type`, JSON primitives keep their type ("1" stays a 
number) and
+ * everything else is taken as a string.
+ */
+export const parseArrayElement = (raw: string, itemsType: unknown): 
ArrayElement | undefined => {
+  const text = raw.trim();
+
+  if (text === "") {
+    return undefined;
+  }
+  switch (itemsType) {
+    case "boolean":
+      return text === "true" || text === "false" ? text === "true" : undefined;
+    case "integer": {
+      const num = Number(text);
+
+      return Number.isInteger(num) ? num : undefined;
+    }
+    case "number": {
+      const num = Number(text);
+
+      return Number.isFinite(num) ? num : undefined;
+    }
+    case "string":
+      return text;
+    default: {
+      try {
+        const parsed = JSON.parse(text) as unknown;

Review Comment:
   good point. the untyped branch goes through `JSON.parse`, so JS number 
semantics apply; quoting `(or items: {"type": "string"})` keeps entries as 
strings. I can make it coerce only when the round-trip is lossless, so 3.10 and 
huge integers stay strings — happy to do that here or as a follow-up.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to