• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / storage / 24474844911

15 Apr 2026 07:46PM UTC coverage: 79.064% (-3.4%) from 82.473%
24474844911

Pull #1024

github

web-flow
Merge 084bba3bd into 2e9e38312
Pull Request #1024: fix: use correct JSON Schema keyword in getSignedURLs response

3035 of 4026 branches covered (75.38%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

4301 existing lines in 99 files now uncovered.

30111 of 37897 relevant lines covered (79.45%)

311.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.5
/src/http/plugins/xml.ts
1
import accepts from '@fastify/accepts'
1✔
2
import { FastifyInstance } from 'fastify'
1✔
3
import fastifyPlugin from 'fastify-plugin'
1✔
4
import xml from 'xml2js'
1✔
5

1✔
6
type XmlParserOptions = { disableContentParser?: boolean; parseAsArray?: string[] }
1✔
7
type RequestError = Error & { statusCode?: number }
1✔
8

1✔
9
function forcePathAsArray(node: unknown, pathSegments: string[]): void {
26✔
10
  if (pathSegments.length === 0 || node === null || node === undefined) {
26!
11
    return
×
UNCOV
12
  }
×
13

26✔
14
  if (Array.isArray(node)) {
26!
15
    node.forEach((item) => forcePathAsArray(item, pathSegments))
×
16
    return
×
UNCOV
17
  }
×
18

26✔
19
  if (typeof node !== 'object') {
26!
20
    return
×
UNCOV
21
  }
×
22

26✔
23
  const [current, ...rest] = pathSegments
26✔
24
  const currentRecord = node as Record<string, unknown>
26✔
25

26✔
26
  if (!(current in currentRecord)) {
26!
27
    return
×
UNCOV
28
  }
×
29

26✔
30
  if (rest.length === 0) {
26✔
31
    const value = currentRecord[current]
13✔
32
    if (value !== undefined && !Array.isArray(value)) {
13✔
33
      currentRecord[current] = [value]
6✔
34
    }
6✔
35
    return
13✔
36
  }
13✔
37

13✔
38
  forcePathAsArray(currentRecord[current], rest)
13✔
39
}
13✔
40

1✔
41
export const xmlParser = fastifyPlugin(
1✔
42
  async function (fastify: FastifyInstance, opts: XmlParserOptions) {
1✔
43
    fastify.register(accepts)
2,860✔
44

2,860✔
45
    if (!opts.disableContentParser) {
2,860✔
46
      fastify.addContentTypeParser(
2,600✔
47
        ['text/xml', 'application/xml'],
2,600✔
48
        { parseAs: 'string' },
2,600✔
49
        (_request, body, done) => {
2,600✔
50
          if (!body) {
87✔
51
            done(null, null)
78✔
52
            return
78✔
53
          }
78✔
54

9✔
55
          xml.parseString(
9✔
56
            body,
9✔
57
            {
9✔
58
              explicitArray: false,
9✔
59
              trim: true,
9✔
60
              valueProcessors: [xml.processors.parseNumbers, xml.processors.parseBooleans],
9✔
61
            },
9✔
62
            (err: Error | null, parsed: unknown) => {
9✔
63
              if (err) {
9✔
64
                const parseError: RequestError = new Error(`Invalid XML payload: ${err.message}`)
1✔
65
                parseError.statusCode = 400
1✔
66
                done(parseError)
1✔
67
                return
1✔
68
              }
1✔
69

8✔
70
              if (parsed && opts.parseAsArray?.length) {
9✔
71
                opts.parseAsArray.forEach((path) => {
8✔
72
                  if (!path) {
13!
73
                    return
×
UNCOV
74
                  }
×
75
                  forcePathAsArray(parsed, path.split('.'))
13✔
76
                })
8✔
77
              }
8✔
78

8✔
79
              done(null, parsed)
8✔
80
            }
8✔
81
          )
9✔
82
        }
9✔
83
      )
2,600✔
84
    }
2,600✔
85

2,860✔
86
    fastify.addHook('preSerialization', async (req, res, payload) => {
2,860✔
87
      const accept = req.accepts()
117✔
88

117✔
89
      const acceptedTypes = ['application/xml', 'text/html']
117✔
90

117✔
91
      if (acceptedTypes.some((allowed) => accept.types(acceptedTypes) === allowed)) {
117✔
92
        res.serializer((payload) => payload)
117✔
93

117✔
94
        const xmlBuilder = new xml.Builder({
117✔
95
          renderOpts: {
117✔
96
            pretty: false,
117✔
97
          },
117✔
98
        })
117✔
99
        const xmlPayload = xmlBuilder.buildObject(payload)
117✔
100
        res.type('application/xml')
117✔
101
        res.header('content-type', 'application/xml; charset=utf-8')
117✔
102
        return xmlPayload
117✔
103
      }
117✔
UNCOV
104

×
UNCOV
105
      return payload
×
106
    })
2,860✔
107
  },
2,860✔
108
  { name: 'xml-parser' }
1✔
109
)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc