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

supabase / storage / 26155689234

20 May 2026 10:06AM UTC coverage: 57.697% (-17.2%) from 74.874%
26155689234

Pull #1115

github

web-flow
Merge d6a84934b into 9a13d3ea2
Pull Request #1115: Encapsulate storage database transaction APIs

2784 of 5519 branches covered (50.44%)

Branch coverage included in aggregate %.

122 of 145 new or added lines in 7 files covered. (84.14%)

1665 existing lines in 69 files now uncovered.

5938 of 9598 relevant lines covered (61.87%)

407.09 hits per line

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

82.05
/src/http/plugins/xml.ts
1
import accepts from '@fastify/accepts'
2
import { ERRORS } from '@internal/errors'
3
import { FastifyInstance } from 'fastify'
4
import fastifyPlugin from 'fastify-plugin'
5
import xml from 'xml2js'
6

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

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

15
  if (Array.isArray(node)) {
48!
16
    node.forEach((item) => forcePathAsArray(item, pathSegments))
×
17
    return
×
18
  }
19

20
  if (typeof node !== 'object') {
48!
21
    return
×
22
  }
23

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

27
  if (!(current in currentRecord)) {
48!
28
    return
×
29
  }
30

31
  if (rest.length === 0) {
48✔
32
    const value = currentRecord[current]
24✔
33
    if (value !== undefined && !Array.isArray(value)) {
24✔
34
      currentRecord[current] = [value]
11✔
35
    }
36
    return
24✔
37
  }
38

39
  forcePathAsArray(currentRecord[current], rest)
24✔
40
}
41

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

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

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

73
              if (parsed && opts.parseAsArray?.length) {
15!
74
                opts.parseAsArray.forEach((path) => {
15✔
75
                  if (!path) {
24!
76
                    return
×
77
                  }
78
                  forcePathAsArray(parsed, path.split('.'))
24✔
79
                })
80
              }
81

82
              done(null, parsed)
15✔
83
            }
84
          )
85
        }
86
      )
87
    }
88

89
    fastify.addHook('preSerialization', async (req, res, payload) => {
2,981✔
90
      const accept = req.accepts()
141✔
91

92
      const acceptedTypes = ['application/xml', 'text/html']
141✔
93

94
      if (acceptedTypes.some((allowed) => accept.types(acceptedTypes) === allowed)) {
141!
95
        res.serializer((payload) => payload)
141✔
96

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

UNCOV
108
      return payload
×
109
    })
110
  },
111
  { name: 'xml-parser' }
112
)
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