Skip to content

$data[$index] == "ID"だと数字の0もtrueになって小文字idに変換されてしまう #128

Description

@RyujiAMANO

https://github.com/netcommons/NetCommons2/blob/develop/html/webapp/components/csv/Main.class.php#L107

if ($data[$index] == "ID") {
    $data[$index] = "id";
}

このコードですが、$data[$index]が数字0だと

0 == "ID"

という比較になり
暗黙の型変換で

0 === intval("ID")

と等価の比較式になりintval("ID")が0なのでtrueとなって数字 0 が id に変換されてしまいます。

下記の様に厳密な比較にすれば回避できます。

if ($data[$index] === "ID") {
    $data[$index] = "id";
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions