Skip to content

Commit 57cd8fc

Browse files
committed
More accurate kernel code check to prevent arbitrary .js files being considered as source code.
1 parent 21e582e commit 57cd8fc

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/Compiler/Outline.gren

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,12 @@ findSourceFilesHelp fsPerm local root =
124124
Just <| findSourceFilesHelp fsPerm (Path.append entry.path local) (Path.append entry.path root)
125125

126126
FileSystem.File ->
127-
if entry.path.extension == "js" || entry.path.extension == "gren" then
128-
Just <| Task.succeed [ { absolute = Path.append entry.path root, relative = Path.append entry.path local } ]
127+
let
128+
fullLocalPath =
129+
Path.append entry.path local
130+
in
131+
if entry.path.extension == "gren" || isKernelCode fullLocalPath then
132+
Just <| Task.succeed [ { absolute = Path.append entry.path root, relative = fullLocalPath } ]
129133

130134
else
131135
Nothing
@@ -138,6 +142,25 @@ findSourceFilesHelp fsPerm local root =
138142
)
139143

140144

145+
isKernelCode : Path -> Bool
146+
isKernelCode path =
147+
if path.extension == "js" then
148+
when Path.parentPath path is
149+
Just parent ->
150+
parent == kernelCodePrefixPath
151+
152+
Nothing ->
153+
False
154+
155+
else
156+
False
157+
158+
159+
kernelCodePrefixPath : Path
160+
kernelCodePrefixPath =
161+
Path.fromPosixString "Gren/Kernel"
162+
163+
141164
readSourceFile : FileSystem.Permission -> { absolute : Path, relative : Path } -> Task FileSystem.Error { path : Path, moduleName : String, source : String }
142165
readSourceFile fsPerm { absolute, relative } =
143166
FileSystem.readFile fsPerm absolute

0 commit comments

Comments
 (0)